Fixes order of opperations issue when drawing messages
This commit is contained in:
parent
cb3bcc9465
commit
e7a1b4e348
108
client.go
108
client.go
|
@ -29,6 +29,7 @@ type client struct {
|
||||||
Width int
|
Width int
|
||||||
Options map[string]string
|
Options map[string]string
|
||||||
Message string
|
Message string
|
||||||
|
MessageIsErr bool
|
||||||
PageState Pages
|
PageState Pages
|
||||||
BookMarks Bookmarks
|
BookMarks Bookmarks
|
||||||
TopBar Headbar
|
TopBar Headbar
|
||||||
|
@ -116,7 +117,8 @@ func (c *client) Draw() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
screen.WriteString("\033[0m")
|
screen.WriteString("\033[0m")
|
||||||
screen.WriteString(c.Message)
|
// TODO using message here breaks on resize, must regenerate
|
||||||
|
screen.WriteString(c.RenderMessage())
|
||||||
screen.WriteString("\n") // for the input line
|
screen.WriteString("\n") // for the input line
|
||||||
screen.WriteString(c.FootBar.Render(c.Width, c.PageState.Position, c.Options["theme"]))
|
screen.WriteString(c.FootBar.Render(c.Width, c.PageState.Position, c.Options["theme"]))
|
||||||
cui.Clear("screen")
|
cui.Clear("screen")
|
||||||
|
@ -237,7 +239,7 @@ func (c *client) routeCommandInput(com *cmdparse.Command) error {
|
||||||
case cmdparse.DOAS:
|
case cmdparse.DOAS:
|
||||||
c.doCommandAs(com.Action, com.Value)
|
c.doCommandAs(com.Action, com.Value)
|
||||||
case cmdparse.DOLINKAS:
|
case cmdparse.DOLINKAS:
|
||||||
// err = doLinkCommandAs(com.Action, com.Target, com.Value)
|
c.doLinkCommandAs(com.Action, com.Target, com.Value)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown command entry!")
|
return fmt.Errorf("Unknown command entry!")
|
||||||
}
|
}
|
||||||
|
@ -361,6 +363,52 @@ func (c *client) doCommandAs(action string, values []string) {
|
||||||
c.SetMessage(fmt.Sprintf("Unknown command structure"), true)
|
c.SetMessage(fmt.Sprintf("Unknown command structure"), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *client) doLinkCommandAs(action, target string, values []string) {
|
||||||
|
num, err := strconv.Atoi(target)
|
||||||
|
if err != nil {
|
||||||
|
c.SetMessage(fmt.Sprintf("Expected link number, got %q", target), true)
|
||||||
|
c.DrawMessage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "ADD", "A":
|
||||||
|
links := c.PageState.History[c.PageState.Position].Links
|
||||||
|
if num >= len(links) {
|
||||||
|
c.SetMessage(fmt.Sprintf("Invalid link id: %s", target), true)
|
||||||
|
c.DrawMessage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bm := make([]string, 0, 5)
|
||||||
|
bm = append(bm, links[num-1])
|
||||||
|
bm = append(bm, values...)
|
||||||
|
msg, err := c.BookMarks.Add(bm)
|
||||||
|
if err != nil {
|
||||||
|
c.SetMessage(err.Error(), true)
|
||||||
|
c.DrawMessage()
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
c.SetMessage(msg, false)
|
||||||
|
c.DrawMessage()
|
||||||
|
}
|
||||||
|
|
||||||
|
err = saveConfig()
|
||||||
|
if err != nil {
|
||||||
|
c.SetMessage("Error saving bookmark to file", true)
|
||||||
|
c.DrawMessage()
|
||||||
|
}
|
||||||
|
if c.BookMarks.IsOpen {
|
||||||
|
c.Draw()
|
||||||
|
}
|
||||||
|
case "WRITE", "W":
|
||||||
|
// TODO get file writing working in some semblance of universal way
|
||||||
|
// return saveFile(links[num-1], strings.Join(values, " "))
|
||||||
|
default:
|
||||||
|
c.SetMessage(fmt.Sprintf("Unknown command structure"), true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *client) getCurrentPageUrl() (string, error) {
|
func (c *client) getCurrentPageUrl() (string, error) {
|
||||||
if c.PageState.Length < 1 {
|
if c.PageState.Length < 1 {
|
||||||
return "", fmt.Errorf("There are no pages in history")
|
return "", fmt.Errorf("There are no pages in history")
|
||||||
|
@ -429,6 +477,9 @@ func (c *client) doLinkCommand(action, target string) {
|
||||||
func (c *client) search() {
|
func (c *client) search() {
|
||||||
c.ClearMessage()
|
c.ClearMessage()
|
||||||
c.ClearMessageLine()
|
c.ClearMessageLine()
|
||||||
|
// TODO handle keeping the full command bar here
|
||||||
|
// like was done for regular command entry
|
||||||
|
// maybe split into separate function
|
||||||
fmt.Print("?")
|
fmt.Print("?")
|
||||||
entry, err := cui.GetLine()
|
entry, err := cui.GetLine()
|
||||||
c.ClearMessageLine()
|
c.ClearMessageLine()
|
||||||
|
@ -439,9 +490,9 @@ func (c *client) search() {
|
||||||
} else if strings.TrimSpace(entry) == "" {
|
} else if strings.TrimSpace(entry) == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
u, err := MakeUrl(c.Options["searchurl"])
|
u, err := MakeUrl(c.Options["searchengine"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.SetMessage("'searchurl' is not set to a valid url", true)
|
c.SetMessage("'searchengine' is not set to a valid url", true)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -507,28 +558,47 @@ func (c *client) displayConfigValue(setting string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) SetMessage(msg string, isError bool) {
|
func (c *client) SetMessage(msg string, isError bool) {
|
||||||
|
c.MessageIsErr = isError
|
||||||
|
c.Message = msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *client) DrawMessage() {
|
||||||
leadIn, leadOut := "", ""
|
leadIn, leadOut := "", ""
|
||||||
if isError {
|
|
||||||
leadIn = "\033[91m"
|
|
||||||
leadOut = "\033[0m"
|
|
||||||
|
|
||||||
if c.Options["theme"] == "normal" {
|
|
||||||
leadIn = "\033[101;7m"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Options["theme"] == "normal" {
|
if c.Options["theme"] == "normal" {
|
||||||
leadIn = "\033[7m"
|
leadIn = "\033[7m"
|
||||||
leadOut = "\033[0m"
|
leadOut = "\033[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Message = fmt.Sprintf("%s%-*.*s%s", leadIn, c.Width, c.Width, msg, leadOut)
|
if c.MessageIsErr {
|
||||||
|
leadIn = "\033[31;1m"
|
||||||
|
leadOut = "\033[0m"
|
||||||
|
|
||||||
|
if c.Options["theme"] == "normal" {
|
||||||
|
leadIn = "\033[41;1;7m"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cui.MoveCursorTo(c.Height-1, 0)
|
||||||
|
fmt.Printf("%s%-*.*s%s", leadIn, c.Width, c.Width, c.Message, leadOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) DrawMessage() {
|
func (c *client) RenderMessage() string {
|
||||||
// c.ClearMessageLine()
|
leadIn, leadOut := "", ""
|
||||||
cui.MoveCursorTo(c.Height-1, 0)
|
if c.Options["theme"] == "normal" {
|
||||||
fmt.Printf("%s", c.Message)
|
leadIn = "\033[7m"
|
||||||
|
leadOut = "\033[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.MessageIsErr {
|
||||||
|
leadIn = "\033[31;1m"
|
||||||
|
leadOut = "\033[0m"
|
||||||
|
|
||||||
|
if c.Options["theme"] == "normal" {
|
||||||
|
leadIn = "\033[41;1;7m"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s%-*.*s%s", leadIn, c.Width, c.Width, c.Message, leadOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ClearMessage() {
|
func (c *client) ClearMessage() {
|
||||||
|
@ -656,7 +726,7 @@ func MakeClient(name string) *client {
|
||||||
// "httpbrowser": "lynx",
|
// "httpbrowser": "lynx",
|
||||||
// "configlocation": userinfo.HomeDir,
|
// "configlocation": userinfo.HomeDir,
|
||||||
// }
|
// }
|
||||||
c := client{0, 0, defaultOptions, "", MakePages(), MakeBookmarks(), MakeHeadbar(name), MakeFootbar()}
|
c := client{0, 0, defaultOptions, "", false, MakePages(), MakeBookmarks(), MakeHeadbar(name), MakeFootbar()}
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
headbar.go
10
headbar.go
|
@ -18,16 +18,6 @@ type Headbar struct {
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
|
||||||
func (h *Headbar) Build(width string) string {
|
|
||||||
// TODO Build out header to specified width
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Headbar) Draw() {
|
|
||||||
// TODO this will actually draw the bar
|
|
||||||
// without having to redraw everything else
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Headbar) Render(width int, theme string) string {
|
func (h *Headbar) Render(width int, theme string) string {
|
||||||
maxMsgWidth := width - len([]rune(h.title)) - 2
|
maxMsgWidth := width - len([]rune(h.title)) - 2
|
||||||
if theme == "inverse" {
|
if theme == "inverse" {
|
||||||
|
|
19
main.go
19
main.go
|
@ -37,17 +37,19 @@ var settings config.Config
|
||||||
|
|
||||||
|
|
||||||
func saveConfig() error {
|
func saveConfig() error {
|
||||||
|
var opts strings.Builder
|
||||||
bkmrks := bombadillo.BookMarks.IniDump()
|
bkmrks := bombadillo.BookMarks.IniDump()
|
||||||
// TODO opts becomes a string builder rather than concat
|
|
||||||
opts := "\n[SETTINGS]\n"
|
opts.WriteString(bkmrks)
|
||||||
|
opts.WriteString("\n[SETTINGS]\n")
|
||||||
for k, v := range bombadillo.Options {
|
for k, v := range bombadillo.Options {
|
||||||
opts += k
|
opts.WriteString(k)
|
||||||
opts += "="
|
opts.WriteRune('=')
|
||||||
opts += v
|
opts.WriteString(v)
|
||||||
opts += "\n"
|
opts.WriteRune('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioutil.WriteFile(bombadillo.Options["configlocation"] + "/.bombadillo.ini", []byte(bkmrks+opts), 0644)
|
return ioutil.WriteFile(bombadillo.Options["configlocation"] + "/.bombadillo.ini", []byte(opts.String()), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() error {
|
func loadConfig() error {
|
||||||
|
@ -100,9 +102,6 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO find out why the loading message
|
|
||||||
// has disappeared on initial load...
|
|
||||||
|
|
||||||
// Start polling for terminal size changes
|
// Start polling for terminal size changes
|
||||||
go bombadillo.GetSize()
|
go bombadillo.GetSize()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue