From 673c0336ec1171953fbaa549cc446f71d5b50c6a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 16 Apr 2023 13:53:47 -0500 Subject: [PATCH] attempt at a fake file Signed-off-by: Jeff Carr --- toolkit/gocui/fakefile.go | 45 +++++++++++++++++++++++++++++++++++++++ toolkit/gocui/showMsg.go | 3 ++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 toolkit/gocui/fakefile.go 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 }