From 97e7ce5ceab002c7cf8b73ddb4853a403ef116ca Mon Sep 17 00:00:00 2001 From: d_m Date: Mon, 17 Feb 2025 14:23:25 -0500 Subject: [PATCH] femto: start long lines --- femto.tal | 56 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/femto.tal b/femto.tal index 13d127a..a35523c 100644 --- a/femto.tal +++ b/femto.tal @@ -14,9 +14,8 @@ |10 @Console [ &vector $2 &read $5 &type $1 &write $1 &error $1 ] |a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] -( MAX file size is currently #ce80, i.e. 52864 bytes ) +( MAX file size is currently #d0000, i.e. 53248 bytes ) -%dbg { #ff .System/debug DEO } %emit { .Console/write DEO } %sp { #2018 DEO } %nl { #0a18 DEO } @@ -36,27 +35,15 @@ %emit-lpar { LIT2 28 18 DEO } %emit-rpar { LIT2 29 18 DEO } %emit-, { LIT2 ", 18 DEO } -%emit-0 { LIT2 "0 18 DEO } -%emit-1 { LIT2 "1 18 DEO } -%emit-2 { LIT2 "2 18 DEO } -%emit-3 { LIT2 "3 18 DEO } -%emit-6 { LIT2 "6 18 DEO } -%emit-7 { LIT2 "7 18 DEO } -%emit-: { LIT2 ": 18 DEO } %emit-; { LIT2 "; 18 DEO } %emit-C { LIT2 "C 18 DEO } %emit-H { LIT2 "H 18 DEO } -%emit-J { LIT2 "J 18 DEO } -%emit-K { LIT2 "K 18 DEO } %emit-[ { LIT2 "[ 18 DEO } %emit-] { LIT2 "] 18 DEO } -%emit-m { LIT2 "m 18 DEO } -%emit-n { LIT2 "n 18 DEO } %emit-~ { LIT2 "~ 18 DEO } %quit! { #01 .System/halt DEO BRK } %quit-restore! { alternate-buffer-off quit! } -%lmargin { #0006 } ( zero page ) |0000 @@ -73,9 +60,11 @@ ( ) ( these can be changed at any time without breaking anything else ) @config [ + &lmargin $2 ( size of the left margin ) &tab-width $2 ( how many spaces to display tab chars ) &tab-adjust $2 ( how many "extra" spaces; tab-width - 1 ) &insert-tabs $1 ( tab key inserts tabs when true ) + &show-linenum $1 ( ) &color $2 ( digits of highlight color in reverse order ) &red $2 ( digits of color for line/EOF markers in reverse order ) ] @@ -85,7 +74,7 @@ ( limit and line-count change when we modify the buffer. ) ( offset and line-offset change when we move the view port. ) @buffer [ - &limit $2 ( last byte of actual data (not including \0) + 1 ) + &limit $2 ( last byte of actual data, not including \0, + 1 ) &line-count $2 ( total number of lines in file ) &offset $2 ( first byte of data visible in terminal ) &line-offset $2 ( first line of text visible in terminal ) @@ -95,8 +84,8 @@ ( ) ( when these change we may need to move the view port as well ) @cursor [ - &col $2 ( current column value 0-n (may exceed lenght of row) ) - &row $2 ( current relative row value, 0-(height-1) ) + &col $2 ( current column value 0-n, may exceed lenght of row ) + &row $2 ( current relative row value, 0-[height-1] ) ] ( tracks overall editor state between events ) @@ -149,9 +138,11 @@ ( init zero page ) #0050 .term/cols STZ2 #0018 .term/rows STZ2 + #0006 .config/lmargin STZ2 #0004 .config/tab-width STZ2 #0003 .config/tab-adjust STZ2 #00 .config/insert-tabs STZ + #01 .config/show-linenum STZ #3333 .config/color STZ2 ( #3133 .config/red STZ2 ) ( #3033 .config/color STZ2 ) @@ -166,12 +157,14 @@ ( import uxn regex library ) ~regex.tal +@lmargin .config/lmargin LDZ2 JMP2r + ( ERROR HANDLING ) ( using errorq will print the given message before causing ) ( the interpreter to halt. ) @errorq ( msg* -> ) - emit-! sp print nl dbg BRK + emit-! sp print nl #ff .System/debug DEO BRK ( open the given file at editor start up ) ( ) @@ -180,11 +173,11 @@ ( TODO: enable closing/opening files with editor already running ) @open-file ( filename* -> ) .File/name DEO2 - #ce81 .File/length DEO2 + #d001 .File/length DEO2 ;data .File/read DEO2 .File/success DEI2 #0000 EQU2 .state/modified STZ - .File/success DEI2 #ce81 LTH2 ?&ok + .File/success DEI2 #d001 LTH2 ?&ok crlf ;messages/input-error print ;filename print crlf quit! @@ -1126,6 +1119,14 @@ @redraw-matches ( -> ) #08 !redraw-add @redraw-all ( -> ) #1f !redraw-add +( for a normal short line this returns: 0, 0 ) +( ) +( for a long line it returns: ) +( - buffer offset: how far past the start of line to begin drawing ) +( - cursor offset: how much to subtract from cursor x coordinate ) +@on-long-line ( -> buf-offset* cursor-offset* ) + #0000 #0000 JMP2r + ( draw the current cursor location ) @draw-cursor ( -> ) .prompt/active LDZ #00 EQU JMP JMP2r @@ -1444,7 +1445,7 @@ LDAk ?{ POP2 JMP2r } LDAk #18 DEO INC2 !print @cur-len ( -> n* ) - cur-line !line-len + cur-line ( >> ) @line-len ( s* -> n* ) #0000 STH2 @@ -1453,6 +1454,17 @@ INC2 INC2r !&loop &end POP2 STH2r JMP2r +@cur-w-len ( -> n* ) + cur-line ( >> ) + +@line-w-len ( s* -> n* ) + LIT2r 0000 + &loop LDAk DUP #00 EQU ?&end + DUP #0a EQU ?&end + #09 NEQ ?{ LIT -config/tab-adjust LDZ2r ADD2r } + INC2 INC2r !&loop + &end POP POP2 STH2r JMP2r + @line-is-visible ( n* -> bool^ ) .buffer/line-offset LDZ2 LTH2k ?&no .term/rows LDZ2 ADD2 LTH2 JMP2r @@ -1702,6 +1714,6 @@ ] ( actual file data to be edited ) -@data $ce80 +@data $d000 ( end of femto.tal )