remove CRLF support, optimizations

This commit is contained in:
~d6 2022-04-06 22:41:25 -04:00
parent 8229c0db14
commit 873419689e
1 changed files with 17 additions and 60 deletions

View File

@ -37,6 +37,7 @@
( blue, magenta, cyan, white )
( TODO: )
( - dollar ($) and caret (^) regex bug )
( - optimize term drawing )
( - get long line truncation/scrolling working )
( - allow line numbers to be toggled off )
@ -44,9 +45,7 @@
( - open file command? )
( - close file command? )
( - move by word/paragraph )
( - search )
( - search&replace )
( - windows line-ending support (CRLF) )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
@ -105,7 +104,6 @@
&tab-width $2 ( how many spaces to display tab chars )
&insert-tabs $1 ( tab key inserts tabs when true )
&color $2 ( digits of highlight color in reverse order )
&line-endings $1 ( 00 = unix, 01 = windows, 80 = mixed )
]
( tracks information related to the buffer's view of data )
@ -272,8 +270,7 @@
@count-c ( c^ -> n* )
#0000 ,&count STR2
STH ;data
&loop ( DUP2 .buffer/limit LDZ2 EQU2 ,&done JCN )
LDAk #00 EQU ,&done JCN
&loop LDAk #00 EQU ,&done JCN
LDAk STHkr NEQ ,&next JCN
,&count LDR2 INC2 ,&count STR2
&next INC2 ,&loop JMP
@ -286,26 +283,7 @@
@setup-linecount ( -> )
#0a ;count-c JSR2 INC2 .buffer/line-count STZ2
#09 ;count-c JSR2 #0000 GTH2 .config/insert-tabs STZ
#0d ;count-c JSR2 DUP2 INC2 .buffer/line-count LDZ2 EQU2 STH
#0000 NEQ2 STHkr #00 EQU AND #80 MUL
STHr ADD DUP .config/line-endings STZ
;strip-cr JCN2 JMP2r
( strip our carriage returns \r )
( )
( a few imporant notes: )
( 1. we need "re-add" these \r bytes when displaying the buffer size )
( 2. we need to "zero out" all the trailing bytes )
@strip-cr ( -> )
;data LIT2r :data ( readpos [writepos] )
&loop LDAk #00 EQU ,&done JCN
LDAk #0d NEQ ,&next JCN INC2 ,&loop JMP
&next LDAk STH2kr STA
INC2 INC2r ,&loop JMP
&done STH2kr .buffer/limit STZ2
&fill DUP2 STH2kr EQU2 ,&exit JCN
#00 STH2kr STA INC2r ,&fill JMP
&exit POP2 POP2r JMP2r
JMP2r
( reads filename from the program's argv )
( )
@ -804,14 +782,6 @@
.config/insert-tabs LDZk #00 EQU SWP STZ
;redraw-statusbar-and-cursor JSR2 ;return JMP2
( toggle whether to use literal tab characters )
( )
( when opening a file, this defaults to 01 if existing tab )
( characters are found, and 00 otherwise. )
@toggle-line-endings ( -> )
.config/line-endings LDZk #00 EQU SWP STZ
;redraw-statusbar-and-cursor JSR2 ;return JMP2
( interpret user input as an escaped sequence )
( )
( called by on-key with state/saw-esc is true )
@ -825,7 +795,6 @@
.state/key LDZ LIT '> EQU ( M-> ) ;goto-end JCN2
.state/key LDZ LIT 'c EQU ( M-c ) ;toggle-color JCN2
.state/key LDZ LIT 'g EQU ( M-g ) ;goto-line JCN2
.state/key LDZ LIT 'l EQU ( M-l ) ;toggle-line-endings JCN2
.state/key LDZ LIT 's EQU ( M-s ) ;regex-search JCN2
.state/key LDZ LIT 't EQU ( M-t ) ;toggle-tabs JCN2
.state/key LDZ LIT 'v EQU ( M-v ) ;page-up JCN2
@ -1178,21 +1147,10 @@
&next LDAk #09 EQU ,&tabs JCN INC2 INC2r ,&loop JMP
&tabs INC2 .config/tab-width LDZ2 STH2 ADD2r ,&loop JMP
( display ** if the buffer has unsaved changes, -- otherwise )
@get-save-status
;messages/unsaved ;messages/saved
.state/modified LDZ JMP SWP2 POP2 JMP2r
( move the terminal cursor to the statusbar line )
@move-to-statusbar ( -> )
#0000 .term/rows LDZ2 ;term-move-cursor JMP2
@buffer-size
.buffer/limit LDZ2 ;data SUB2
.config/line-endings LDZ #00 EQU ,&done JCN
.buffer/line-count LDZ2 #0001 SUB2 ADD2
&done JMP2r
( draw the full statusbar )
@draw-statusbar ( -> )
;move-to-statusbar JSR2
@ -1203,11 +1161,13 @@
&done POP2 POP2 POP2r ( )
;move-to-statusbar JSR2
;get-save-status JSR2 ;print JSR2
( display ** if the buffer has unsaved changes, -- otherwise )
#2d .state/modified LDZ #00 NEQ #03 MUL SUB DUP emit emit sp
;filename ;print JSR2
sp emit-[
( .buffer/limit LDZ2 ;data SUB2 ;emit-dec2 JSR2 )
;buffer-size JSR2 ;emit-dec2 JSR2
.buffer/limit LDZ2 ;data SUB2 ;emit-dec2 JSR2
;messages/bytes ;print JSR2
sp
.buffer/line-count LDZ2 ;emit-dec2 JSR2
@ -1218,8 +1178,6 @@
.cursor/row LDZ2 INC2 ;emit-dec2 JSR2
emit-) sp emit-[
LIT 's .config/insert-tabs LDZ ADD emit
emit-:
LIT 'u .config/line-endings LDZ #00 NEQ #02 MUL ADD emit ( "u" or "w" )
emit-]
;emit-reset JMP2
@ -1250,6 +1208,7 @@
&fail POP2 #0000
&done POP2r JMP2r
( TODO: this doesn't handle tabs correctly )
@draw-region ( offset* limit* col* row* -> )
OVR2 ( offset limit col row col )
.term/cols LDZ2 SWP2 SUB2 STH2 ( offset limit col row [cols-col] )
@ -1481,17 +1440,17 @@
@abs-line ( y* -> s* )
;data SWP2 ;line-to-pos JMP2
( find string pointer for absolute y coordinate )
@rel-line ( y* -> s* )
.buffer/offset LDZ2 SWP2 ;line-to-pos JMP2
( return a pointer to the current line )
@cur-line ( -> s* )
.cursor/row LDZ2 .buffer/line-offset LDZ2 SUB2k
.term/rows LDZ2 LTH2 ,&ok JCN
.cursor/row LDZ2 .buffer/line-offset LDZ2 LTH2k ,&early JCN
( if cursor/row is later than line-offset )
( we can save some time by starting at )
( buffer/offset instead of the beginning )
SUB2 .buffer/offset LDZ2 SWP2 ;line-to-pos JMP2
&early
( if cursor/row is earlier than line-offset )
( we need to use the absolute y coordinate )
POP2 ;abs-line JMP2
&ok
SUB2 ;rel-line JMP2
( return a pointer to the current cursor position )
@cur-pos ( -> s* )
@ -1583,8 +1542,6 @@
&quit-prompt "Save 20 "modified 20 "file 20 "(y/n)? 20 00
&unknown-input "Unknown 20 "input: 20 00
&no-matches-found "No 20 "matches 20 "found: 20 00
&saved "-- 20 00
&unsaved "** 20 00
&term-size-parse-error "error 20 "parsing 20 "term 20 "size 00
&rel-line-error "invalid 20 "relative 20 "line 20 "number 00
]