From c5f3a043b3414fba085634251597dce48981b8f7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 16 Apr 2023 20:55:13 -0500 Subject: [PATCH] gocui: fake file potential example. can I send this to open()? Signed-off-by: Jeff Carr --- toolkit/gocui/fakefile.go | 23 ++++++++++++++++++----- toolkit/gocui/showMsg.go | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/toolkit/gocui/fakefile.go b/toolkit/gocui/fakefile.go index 2cdfca1..c6b8877 100644 --- a/toolkit/gocui/fakefile.go +++ b/toolkit/gocui/fakefile.go @@ -3,22 +3,25 @@ package main import ( "bytes" "io" + "errors" ) type FakeFile struct { - buffer bytes.Buffer + reader *bytes.Reader + buffer *bytes.Buffer offset int64 } func (f *FakeFile) Read(p []byte) (n int, err error) { - n, err = f.buffer.ReadAt(p, f.offset) + n, err = f.reader.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) + n, err = f.buffer.Write(p) f.offset += int64(n) + f.reader.Reset(f.buffer.Bytes()) return n, err } @@ -33,13 +36,23 @@ func (f *FakeFile) Seek(offset int64, whence int) (int64, error) { case io.SeekEnd: newOffset = int64(f.buffer.Len()) + offset default: - return 0, io.ErrInvalidWhence + return 0, errors.New("Seek: whence not at start,current or end") } + // never can get here right? if newOffset < 0 { - return 0, io.ErrInvalidWhence + return 0, errors.New("Seek: offset < 0") } f.offset = newOffset return f.offset, nil } + +func NewFakeFile() *FakeFile { + buf := &bytes.Buffer{} + return &FakeFile{ + reader: bytes.NewReader(buf.Bytes()), + buffer: buf, + offset: 0, + } +} diff --git a/toolkit/gocui/showMsg.go b/toolkit/gocui/showMsg.go index f3cd0e7..e749834 100644 --- a/toolkit/gocui/showMsg.go +++ b/toolkit/gocui/showMsg.go @@ -45,6 +45,7 @@ func showMsg(g *gocui.Gui, v *gocui.View) error { fmt.Fprintln(v, l) } // g.SetViewOnTop("msg") - g.SetViewOnBottom("msg") + g.SetViewBeneath("msg", "help", 24) + // g.SetViewOnBottom("msg") return nil }