@@ -690,7 +690,7 @@ func (v *View) makeWriteable(x, y int) {
690
690
v .lines = append (v .lines , nil )
691
691
}
692
692
}
693
- // cell `x` must not be index-able (that's why `<`)
693
+ // cell `x` need not be index-able (that's why `<`)
694
694
// append should be used by `lines[y]` user if he wants to write beyond `x`
695
695
for len (v .lines [y ]) < x {
696
696
if cap (v .lines [y ]) > len (v .lines [y ]) {
@@ -726,14 +726,6 @@ func (v *View) writeCells(x, y int, cells []cell) {
726
726
v .lines [y ] = line [:newLen ]
727
727
}
728
728
729
- // readCell gets cell at specified location (x, y)
730
- func (v * View ) readCell (x , y int ) (cell , bool ) {
731
- if y < 0 || y >= len (v .lines ) || x < 0 || x >= len (v .lines [y ]) {
732
- return cell {}, false
733
- }
734
- return v.lines [y ][x ], true
735
- }
736
-
737
729
// Write appends a byte slice into the view's internal buffer. Because
738
730
// View implements the io.Writer interface, it can be passed as parameter
739
731
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
@@ -762,31 +754,28 @@ func (v *View) writeRunes(p []rune) {
762
754
// Fill with empty cells, if writing outside current view buffer
763
755
v .makeWriteable (v .wx , v .wy )
764
756
757
+ finishLine := func () {
758
+ v .autoRenderHyperlinksInCurrentLine ()
759
+ if v .wx >= len (v .lines [v .wy ]) {
760
+ v .writeCells (v .wx , v .wy , []cell {{
761
+ chr : 0 ,
762
+ fgColor : 0 ,
763
+ bgColor : 0 ,
764
+ }})
765
+ }
766
+ }
767
+
765
768
for _ , r := range p {
766
769
switch r {
767
770
case '\n' :
768
- v .autoRenderHyperlinksInCurrentLine ()
769
- if c , ok := v .readCell (v .wx + 1 , v .wy ); ! ok || c .chr == 0 {
770
- v .writeCells (v .wx , v .wy , []cell {{
771
- chr : 0 ,
772
- fgColor : 0 ,
773
- bgColor : 0 ,
774
- }})
775
- }
771
+ finishLine ()
776
772
v .wx = 0
777
773
v .wy ++
778
774
if v .wy >= len (v .lines ) {
779
775
v .lines = append (v .lines , nil )
780
776
}
781
777
case '\r' :
782
- v .autoRenderHyperlinksInCurrentLine ()
783
- if c , ok := v .readCell (v .wx , v .wy ); ! ok || c .chr == 0 {
784
- v .writeCells (v .wx , v .wy , []cell {{
785
- chr : 0 ,
786
- fgColor : 0 ,
787
- bgColor : 0 ,
788
- }})
789
- }
778
+ finishLine ()
790
779
v .wx = 0
791
780
default :
792
781
truncateLine , cells := v .parseInput (r , v .wx , v .wy )
0 commit comments