prompt is partially working

This commit is contained in:
~d6 2022-03-23 21:46:59 -04:00
parent f46c813bf5
commit af7c3993fc
1 changed files with 96 additions and 23 deletions

119
femto.tal
View File

@ -102,7 +102,7 @@
@prompt [ @prompt [
&active $1 ( is prompt currently active? ) &active $1 ( is prompt currently active? )
&vector $2 ( what code to run when user responds ) &vector $2 ( what code to run when user responds )
&string $20 ( string to print for the prompt ) &string $2 ( string to print for the prompt )
] ]
@tmp [ @tmp [
@ -343,7 +343,7 @@
#0a ;cur-pos JSR2 ;shift-right JSR2 #0a ;cur-pos JSR2 ;shift-right JSR2
#0000 .cursor/col STZ2 #0000 .cursor/col STZ2
;inc-row JSR2 ;inc-row JSR2
.buffer/line-count LDZ2k INC2 SWP2 STA2 .buffer/line-count LDZ2k INC2 ROT STZ2
;ensure-visible-cursor JSR2 ;ensure-visible-cursor JSR2
;draw-all JSR2 ;draw-all JSR2
BRK BRK
@ -371,7 +371,7 @@
;cur-abs-row JSR2 #0001 SUB2 ;cur-abs-row JSR2 #0001 SUB2
;jump-to-line JSR2 ( TODO: fix weird eof behavior ) ;jump-to-line JSR2 ( TODO: fix weird eof behavior )
;cur-len JSR2 .cursor/col STZ2 ;cur-len JSR2 .cursor/col STZ2
.buffer/line-count LDZ2k #0001 SUB2 SWP2 STA2 .buffer/line-count LDZ2k #0001 SUB2 ROT STZ2
&finish &finish
;cur-pos JSR2 ;shift-left JSR2 ;cur-pos JSR2 ;shift-left JSR2
;draw-all JSR2 ;draw-all JSR2
@ -383,7 +383,7 @@
;cur-pos JSR2 LDAk STH ( cur [c] ) ;cur-pos JSR2 LDAk STH ( cur [c] )
;shift-left JSR2 ( [c] ) ;shift-left JSR2 ( [c] )
STHr #0a NEQ ,&not-newline JCN STHr #0a NEQ ,&not-newline JCN
.buffer/line-count LDZ2k #0001 SUB2 SWP2 STA2 .buffer/line-count LDZ2k #0001 SUB2 ROT STZ2
&not-newline ;draw-all JSR2 &not-newline ;draw-all JSR2
&skip BRK &skip BRK
@ -446,6 +446,64 @@
@debug @debug
;rel-line-error ;error! JMP2 ;rel-line-error ;error! JMP2
@move-to-message-line ( -> )
#0002 .term/rows LDZ2 #0002 ADD2 ;term-move-cursor JMP2
( TODO: need to create draw-prompt and call it from draw-all )
( when called vector should end in BRK )
@start-prompt ( prompt* default* vector* -> )
.prompt/active LDZ ,&is-active JCN
#01 .prompt/active STZ ( prompt/active <- 1 )
.prompt/vector STZ2 ( prompt/vector <- vector )
DUP2 ;tmp/data ;str-copy JSR2 ( tmp/data <- default )
;tmp/data ;str-len JSR2 ADD2 ( data+len(default) )
.tmp/pos STZ2 ( tmp/pos <- data+len(default) )
.prompt/string STZ2 ( prompt/string <- prompt )
JMP2r
&is-active
#0000 DIV
( ends prompt without calling vector )
@cancel-prompt ( -> )
.prompt/active LDZ ,&is-active JCN
#0000 DIV
&is-active
#00 .prompt/active STZ
;draw-prompt JSR2
;draw-cursor JSR2
BRK
( when called vector should end in BRK )
@finish-prompt ( -> )
.prompt/active LDZ ,&is-active JCN
#0000 DIV
&is-active
#00 .prompt/active STZ
;draw-prompt JSR2
;draw-cursor JSR2
.prompt/vector LDZ2 JMP2
@save
;messages/save-prompt ;filename ;do-save ;start-prompt JSR2
;draw-prompt JSR2
;draw-cursor JSR2
BRK
@do-save ( -> )
.buffer/limit LDZ2 ;data SUB2 STH2 ( [size] )
;tmp/data .File/name DEO2
STH2kr .File/length DEO2
;data .File/write DEO2
;move-to-message-line JSR2
.File/success DEI2 STH2r EQU2 ( ok? ) ,&ok JCN
;messages/save-failed ,&finish JMP
&ok ;messages/save-ok
&finish ;print JSR2 ;tmp/data ;print JSR2 BRK
@tmp-file-name "file.tmp 00
( TODO: M-f and M-b for next/previous word ) ( TODO: M-f and M-b for next/previous word )
( M-n and M-p for next/previous paragraph ) ( M-n and M-p for next/previous paragraph )
( maybe M-% for search&replace ) ( maybe M-% for search&replace )
@ -457,28 +515,16 @@
.Console/read DEI LIT 'v EQU ( M-v ) ;page-up JCN2 .Console/read DEI LIT 'v EQU ( M-v ) ;page-up JCN2
BRK BRK
@move-to-message-line ( -> ) @on-key-prompt
#0002 .term/rows LDZ2 #0002 ADD2 ;term-move-cursor JMP2 .Console/read DEI #07 EQU ( C-g ) ;cancel-prompt JCN2
.Console/read DEI #0d EQU ( \r ) ;finish-prompt JCN2
( TODO: filename prmopt ) BRK
@save ( -> )
.buffer/limit LDZ2 ;data SUB2 STH2 ( [size] )
;tmp-file-name .File/name DEO2
STH2kr .File/length DEO2
;data .File/write DEO2
;move-to-message-line JSR2
.File/success DEI2 STH2r EQU2 ( ok? ) ,&ok JCN
;messages/save-failed ,&finish JMP
&ok ;messages/save-ok
&finish ;print JSR2 BRK
@tmp-file-name "file.tmp 00
( TODO: C-g or C-h for help ) ( TODO: C-g or C-h for help )
( TODO: C-s for search ) ( TODO: C-s for search )
( TODO: tab input? ) ( TODO: tab input? )
@on-key @on-key
.prompt/active LDZ ;on-key-prompt JCN2
.state/saw-esc LDZ ;on-key-escaped JCN2 .state/saw-esc LDZ ;on-key-escaped JCN2
.Console/read DEI #01 EQU ( C-a ) ;bol JCN2 .Console/read DEI #01 EQU ( C-a ) ;bol JCN2
.Console/read DEI #02 EQU ( C-b ) ;back JCN2 .Console/read DEI #02 EQU ( C-b ) ;back JCN2
@ -530,6 +576,7 @@
INC2 ,&loop JMP INC2 ,&loop JMP
@draw-cursor ( -> ) @draw-cursor ( -> )
.prompt/active LDZ ,&on-prompt JCN
;cur-w-col JSR2 .term/lmargin LDZ2 ADD2 ;cur-w-col JSR2 .term/lmargin LDZ2 ADD2
.term/cols LDZ2 LTH2 ,&ok JCN .term/cols LDZ2 LTH2 ,&ok JCN
( we have a long line ) ( we have a long line )
@ -538,6 +585,8 @@
;cur-w-col JSR2 .term/lmargin LDZ2 ADD2 ;cur-w-col JSR2 .term/lmargin LDZ2 ADD2
;cur-rel-row JSR2 ;cur-rel-row JSR2
;term-move-cursor JMP2 ;term-move-cursor JMP2
&on-prompt
JMP2r
@draw-statusbar ( -> ) @draw-statusbar ( -> )
#0000 .term/rows LDZ2 ;term-move-cursor JSR2 #0000 .term/rows LDZ2 ;term-move-cursor JSR2
@ -568,6 +617,18 @@
;emit-reset JSR2 ;emit-reset JSR2
JMP2r JMP2r
@draw-prompt ( -> )
#0000 .term/rows LDZ2 INC2 ;term-move-cursor JSR2
ansi LIT '2 emit LIT 'K emit
.prompt/active LDZ ,&is-active JCN
JMP2r
&is-active
;emit-color-bold JSR2
.prompt/string LDZ2 ;print JSR2
;emit-reset JSR2
;tmp/data ;print JSR2
JMP2r
@draw-linenum ( n* -> ) @draw-linenum ( n* -> )
;emit-reset JSR2 ;emit-reset JSR2
ansi .config/color LDZ2 emit emit LIT 'm emit ansi .config/color LDZ2 emit emit LIT 'm emit
@ -592,6 +653,9 @@
@emit-color-reverse ( -> ) @emit-color-reverse ( -> )
ansi .config/color LDZ2 emit emit LIT2 '7 '; emit emit LIT 'm emit JMP2r ansi .config/color LDZ2 emit emit LIT2 '7 '; emit emit LIT 'm emit JMP2r
@emit-color-bold ( -> )
ansi .config/color LDZ2 emit emit LIT2 '1 '; emit emit LIT 'm emit JMP2r
@draw-all ( -> ) @draw-all ( -> )
;term-erase-all JSR2 ;term-erase-all JSR2
#0000 #0000 ;term-move-cursor JSR2 #0000 #0000 ;term-move-cursor JSR2
@ -631,6 +695,7 @@
&done POP2 POP2r POP2r &done POP2 POP2r POP2r
;emit-reset JSR2 ;emit-reset JSR2
;draw-statusbar JSR2 ;draw-statusbar JSR2
;draw-prompt JSR2
;draw-cursor JSR2 ;draw-cursor JSR2
JMP2r JMP2r
@ -642,6 +707,13 @@
&done POP2 #00 STH2r STA &done POP2 #00 STH2r STA
JMP2r JMP2r
@str-len ( s* -> n* )
LIT2r 0000
&loop LDAk #00 EQU ,&done JCN
INC2 INC2r ,&loop JMP
&done POP2 STH2r
JMP2r
@print ( s* -> ) @print ( s* -> )
&loop LDAk #00 EQU ,&eof JCN &loop LDAk #00 EQU ,&eof JCN
LDAk #18 DEO INC2 ,&loop JMP LDAk #18 DEO INC2 ,&loop JMP
@ -839,9 +911,10 @@
( various string constants used as messages for the user ) ( various string constants used as messages for the user )
@messages [ &input-error "input 20 "error: 20 00 @messages [ &input-error "input 20 "error: 20 00
&bytes 20 "bytes, 00 &bytes 20 "bytes, 00
&save-ok "saved 00 &save-ok "saved 20 00
&save-failed "failed 00 &save-failed "failed 20 "to 20 "save 00
&lines 20 "lines] 00 &lines 20 "lines] 00
&save-prompt "File 20 "Name 20 "to 20 "Write: 20 00
&saved "-- 20 00 &saved "-- 20 00
&unsaved "** 20 00 ] &unsaved "** 20 00 ]