diff options
| author | Jeff Carr <[email protected]> | 2023-04-16 13:53:47 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-04-16 13:53:47 -0500 |
| commit | 34146ffd1036a3944767f25556a9117d5eaffd0d (patch) | |
| tree | f7b06cd8219ffae0496ef508a997ace7dea048d5 /toolkit | |
| parent | 20987c868a7f290b92f811e07084aae5f38ff170 (diff) | |
attempt at a fake file
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit')
| -rw-r--r-- | toolkit/gocui/fakefile.go | 45 | ||||
| -rw-r--r-- | toolkit/gocui/showMsg.go | 3 |
2 files changed, 47 insertions, 1 deletions
diff --git a/toolkit/gocui/fakefile.go b/toolkit/gocui/fakefile.go new file mode 100644 index 0000000..2cdfca1 --- /dev/null +++ b/toolkit/gocui/fakefile.go @@ -0,0 +1,45 @@ +package main + +import ( + "bytes" + "io" +) + +type FakeFile struct { + buffer bytes.Buffer + offset int64 +} + +func (f *FakeFile) Read(p []byte) (n int, err error) { + n, err = f.buffer.ReadAt(p, f.offset) + f.offset += int64(n) + return n, err +} + +func (f *FakeFile) Write(p []byte) (n int, err error) { + n, err = f.buffer.WriteAt(p, f.offset) + f.offset += int64(n) + return n, err +} + +func (f *FakeFile) Seek(offset int64, whence int) (int64, error) { + newOffset := f.offset + + switch whence { + case io.SeekStart: + newOffset = offset + case io.SeekCurrent: + newOffset += offset + case io.SeekEnd: + newOffset = int64(f.buffer.Len()) + offset + default: + return 0, io.ErrInvalidWhence + } + + if newOffset < 0 { + return 0, io.ErrInvalidWhence + } + + f.offset = newOffset + return f.offset, nil +} diff --git a/toolkit/gocui/showMsg.go b/toolkit/gocui/showMsg.go index 2a0a873..f3cd0e7 100644 --- a/toolkit/gocui/showMsg.go +++ b/toolkit/gocui/showMsg.go @@ -44,6 +44,7 @@ func showMsg(g *gocui.Gui, v *gocui.View) error { l += "foo\n" + "bar\n" fmt.Fprintln(v, l) } - g.SetViewOnTop("msg") + // g.SetViewOnTop("msg") + g.SetViewOnBottom("msg") return nil } |
