summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-09-27 22:19:11 +0200
committertomsmeding <tom.smeding@gmail.com>2016-09-27 22:19:11 +0200
commit0bb9d719c86db457439ee8e012eb141c76eed307 (patch)
tree8bf572e09c977aef7b86446a8390b071120e75c9
parentce00424be3963c97ef43d52e87a2da380559536c (diff)
Add tape current cell highlight
-rw-r--r--bfinter.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/bfinter.c b/bfinter.c
index cf4a102..587471c 100644
--- a/bfinter.c
+++ b/bfinter.c
@@ -62,9 +62,12 @@ byte tape_get(const Tape *tape,int idx){
return tape->buf[idx];
}
-void tape_print(const Tape *tape){
+// pass curidx=-1 for no highlight
+void tape_print(const Tape *tape,int curidx){
for(int i=0;i<=tape->maxidx;i++){
+ if(i==curidx)printf("\x1B[4m");
printf("%3d ",tape->buf[i]);
+ if(i==curidx)printf("\x1B[0m");
}
putchar('\n');
}
@@ -153,7 +156,7 @@ void interpret(const char *source,const int sourcelen,const Jumpmap *jm){
case ',': tape_set(tape,mp,(byte)getchar()); break;
case '[': if(!tape_get(tape,mp))ip=jm_get(jm,ip); break;
case ']': if(tape_get(tape,mp))ip=jm_get(jm,ip); break;
- case '#': tape_print(tape); break;
+ case '#': tape_print(tape,mp); break;
case '0': tape_set(tape,mp,0); break;
case '^': ip++; tape_set(tape,mp,tape_get(tape,mp)+(byte)source[ip]); break;
@@ -378,6 +381,7 @@ int main(int argc,char **argv){
Jumpmap *jm=jm_make(source,sourcelen);
+ clearerr(stdin);
interpret(source,sourcelen,jm);
jm_destroy(jm);