@@ -655,12 +655,15 @@ var vkKeys = map[uint16]Key{
655
655
func getu32 (v []byte ) uint32 {
656
656
return uint32 (v [0 ]) + (uint32 (v [1 ]) << 8 ) + (uint32 (v [2 ]) << 16 ) + (uint32 (v [3 ]) << 24 )
657
657
}
658
+
658
659
func geti32 (v []byte ) int32 {
659
660
return int32 (getu32 (v ))
660
661
}
662
+
661
663
func getu16 (v []byte ) uint16 {
662
664
return uint16 (v [0 ]) + (uint16 (v [1 ]) << 8 )
663
665
}
666
+
664
667
func geti16 (v []byte ) int16 {
665
668
return int16 (getu16 (v ))
666
669
}
@@ -938,7 +941,7 @@ func (s *cScreen) mapStyle(style Style) uint16 {
938
941
return attr
939
942
}
940
943
941
- func (s * cScreen ) sendVtStyle (style Style ) {
944
+ func (s * cScreen ) makeVtStyle (style Style ) string {
942
945
esc := & strings.Builder {}
943
946
944
947
fg , bg , attrs := style .fg , style .bg , style .attrs
@@ -998,30 +1001,40 @@ func (s *cScreen) sendVtStyle(style Style) {
998
1001
esc .WriteString (vtExitUrl )
999
1002
}
1000
1003
1001
- s . emitVtString ( esc .String () )
1004
+ return esc .String ()
1002
1005
}
1003
1006
1004
- func (s * cScreen ) writeString (x , y int , style Style , ch []uint16 ) {
1007
+ func (s * cScreen ) sendVtStyle (style Style ) {
1008
+ s .emitVtString (s .makeVtStyle (style ))
1009
+ }
1010
+
1011
+ func (s * cScreen ) writeString (x , y int , style Style , vtBuf , ch []uint16 ) {
1005
1012
// we assume the caller has hidden the cursor
1006
1013
if len (ch ) == 0 {
1007
1014
return
1008
1015
}
1009
- s .setCursorPos (x , y , s .vten )
1010
1016
1011
1017
if s .vten {
1012
- s .sendVtStyle (style )
1018
+ vtBuf = append (vtBuf , utf16 .Encode ([]rune (fmt .Sprintf (vtCursorPos , y + 1 , x + 1 )))... )
1019
+ styleStr := s .makeVtStyle (style )
1020
+ vtBuf = append (vtBuf , utf16 .Encode ([]rune (styleStr ))... )
1021
+ vtBuf = append (vtBuf , ch ... )
1022
+ _ = syscall .WriteConsole (s .out , & vtBuf [0 ], uint32 (len (vtBuf )), nil , nil )
1023
+ vtBuf = vtBuf [:0 ]
1013
1024
} else {
1025
+ s .setCursorPos (x , y , s .vten )
1014
1026
_ , _ , _ = procSetConsoleTextAttribute .Call (
1015
1027
uintptr (s .out ),
1016
1028
uintptr (s .mapStyle (style )))
1029
+ _ = syscall .WriteConsole (s .out , & ch [0 ], uint32 (len (ch )), nil , nil )
1017
1030
}
1018
- _ = syscall .WriteConsole (s .out , & ch [0 ], uint32 (len (ch )), nil , nil )
1019
1031
}
1020
1032
1021
1033
func (s * cScreen ) draw () {
1022
1034
// allocate a scratch line bit enough for no combining chars.
1023
1035
// if you have combining characters, you may pay for extra allocations.
1024
1036
buf := make ([]uint16 , 0 , s .w )
1037
+ var vtBuf []uint16
1025
1038
wcs := buf [:]
1026
1039
lstyle := styleInvalid
1027
1040
@@ -1040,7 +1053,7 @@ func (s *cScreen) draw() {
1040
1053
// write out any data queued thus far
1041
1054
// because we are going to skip over some
1042
1055
// cells, or because we need to change styles
1043
- s .writeString (lx , ly , lstyle , wcs )
1056
+ s .writeString (lx , ly , lstyle , vtBuf , wcs )
1044
1057
wcs = buf [0 :0 ]
1045
1058
lstyle = StyleDefault
1046
1059
if ! dirty {
@@ -1067,7 +1080,7 @@ func (s *cScreen) draw() {
1067
1080
}
1068
1081
x += width - 1
1069
1082
}
1070
- s .writeString (lx , ly , lstyle , wcs )
1083
+ s .writeString (lx , ly , lstyle , vtBuf , wcs )
1071
1084
wcs = buf [0 :0 ]
1072
1085
lstyle = styleInvalid
1073
1086
}
0 commit comments