more lint

This commit is contained in:
Michael Yang 2024-05-29 18:22:03 -07:00
parent 42660466f8
commit 8ce4032e72
2 changed files with 8 additions and 18 deletions

View file

@ -52,7 +52,6 @@ func (b *Buffer) GetLineSpacing(line int) bool {
} }
return hasSpace.(bool) return hasSpace.(bool)
} }
func (b *Buffer) MoveLeft() { func (b *Buffer) MoveLeft() {
@ -117,15 +116,12 @@ func (b *Buffer) MoveRight() {
if b.DisplayPos%b.LineWidth == 0 { if b.DisplayPos%b.LineWidth == 0 {
fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt()))) fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())))
} else if (b.DisplayPos-rLength)%b.LineWidth == b.LineWidth-1 && hasSpace { } else if (b.DisplayPos-rLength)%b.LineWidth == b.LineWidth-1 && hasSpace {
fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())+rLength)) fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())+rLength))
b.DisplayPos += 1 b.DisplayPos += 1
} else if b.LineHasSpace.Size() > 0 && b.DisplayPos%b.LineWidth == b.LineWidth-1 && hasSpace { } else if b.LineHasSpace.Size() > 0 && b.DisplayPos%b.LineWidth == b.LineWidth-1 && hasSpace {
fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt()))) fmt.Printf(CursorDown + CursorBOL + cursorRightN(len(b.Prompt.prompt())))
b.DisplayPos += 1 b.DisplayPos += 1
} else { } else {
fmt.Print(cursorRightN(rLength)) fmt.Print(cursorRightN(rLength))
} }
@ -185,7 +181,7 @@ func (b *Buffer) MoveToEnd() {
func (b *Buffer) DisplaySize() int { func (b *Buffer) DisplaySize() int {
sum := 0 sum := 0
for i := 0; i < b.Buf.Size(); i++ { for i := range b.Buf.Size() {
if e, ok := b.Buf.Get(i); ok { if e, ok := b.Buf.Get(i); ok {
if r, ok := e.(rune); ok { if r, ok := e.(rune); ok {
sum += runewidth.RuneWidth(r) sum += runewidth.RuneWidth(r)
@ -197,7 +193,6 @@ func (b *Buffer) DisplaySize() int {
} }
func (b *Buffer) Add(r rune) { func (b *Buffer) Add(r rune) {
if b.Pos == b.Buf.Size() { if b.Pos == b.Buf.Size() {
b.AddChar(r, false) b.AddChar(r, false)
} else { } else {
@ -210,7 +205,6 @@ func (b *Buffer) AddChar(r rune, insert bool) {
b.DisplayPos += rLength b.DisplayPos += rLength
if b.Pos > 0 { if b.Pos > 0 {
if b.DisplayPos%b.LineWidth == 0 { if b.DisplayPos%b.LineWidth == 0 {
fmt.Printf("%c", r) fmt.Printf("%c", r)
fmt.Printf("\n%s", b.Prompt.AltPrompt) fmt.Printf("\n%s", b.Prompt.AltPrompt)
@ -235,7 +229,6 @@ func (b *Buffer) AddChar(r rune, insert bool) {
} else { } else {
b.LineHasSpace.Add(true) b.LineHasSpace.Add(true)
} }
} else { } else {
fmt.Printf("%c", r) fmt.Printf("%c", r)
} }
@ -356,7 +349,6 @@ func (b *Buffer) drawRemaining() {
func (b *Buffer) Remove() { func (b *Buffer) Remove() {
if b.Buf.Size() > 0 && b.Pos > 0 { if b.Buf.Size() > 0 && b.Pos > 0 {
if e, ok := b.Buf.Get(b.Pos - 1); ok { if e, ok := b.Buf.Get(b.Pos - 1); ok {
if r, ok := e.(rune); ok { if r, ok := e.(rune); ok {
rLength := runewidth.RuneWidth(r) rLength := runewidth.RuneWidth(r)
@ -382,7 +374,6 @@ func (b *Buffer) Remove() {
} else { } else {
fmt.Print(" " + CursorLeft) fmt.Print(" " + CursorLeft)
} }
} else if (b.DisplayPos-rLength)%b.LineWidth == 0 && hasSpace { } else if (b.DisplayPos-rLength)%b.LineWidth == 0 && hasSpace {
fmt.Printf(CursorBOL + ClearToEOL) fmt.Printf(CursorBOL + ClearToEOL)
fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width)) fmt.Printf(CursorUp + CursorBOL + cursorRightN(b.Width))
@ -391,10 +382,9 @@ func (b *Buffer) Remove() {
b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1) b.LineHasSpace.Remove(b.DisplayPos/b.LineWidth - 1)
} }
b.DisplayPos -= 1 b.DisplayPos -= 1
} else { } else {
fmt.Print(cursorLeftN(rLength)) fmt.Print(cursorLeftN(rLength))
for i := 0; i < rLength; i++ { for range rLength {
fmt.Print(" ") fmt.Print(" ")
} }
fmt.Print(cursorLeftN(rLength)) fmt.Print(cursorLeftN(rLength))
@ -525,7 +515,7 @@ func (b *Buffer) Replace(r []rune) {
fmt.Printf(CursorBOL + ClearToEOL) fmt.Printf(CursorBOL + ClearToEOL)
for i := 0; i < lineNums; i++ { for range lineNums {
fmt.Print(CursorUp + CursorBOL + ClearToEOL) fmt.Print(CursorUp + CursorBOL + ClearToEOL)
} }

View file

@ -26,20 +26,20 @@ func createTestFile(t *testing.T, name string) string {
t.Helper() t.Helper()
f, err := os.CreateTemp(t.TempDir(), name) f, err := os.CreateTemp(t.TempDir(), name)
assert.NoError(t, err) require.NoError(t, err)
defer f.Close() defer f.Close()
err = binary.Write(f, binary.LittleEndian, []byte("GGUF")) err = binary.Write(f, binary.LittleEndian, []byte("GGUF"))
assert.NoError(t, err) require.NoError(t, err)
err = binary.Write(f, binary.LittleEndian, uint32(3)) err = binary.Write(f, binary.LittleEndian, uint32(3))
assert.NoError(t, err) require.NoError(t, err)
err = binary.Write(f, binary.LittleEndian, uint64(0)) err = binary.Write(f, binary.LittleEndian, uint64(0))
assert.NoError(t, err) require.NoError(t, err)
err = binary.Write(f, binary.LittleEndian, uint64(0)) err = binary.Write(f, binary.LittleEndian, uint64(0))
assert.NoError(t, err) require.NoError(t, err)
return f.Name() return f.Name()
} }