Added focus shifting between windows redid how draws work

This commit is contained in:
sloumdrone 2019-04-10 22:29:10 -07:00
parent e0083ae444
commit 88898c5b4a
5 changed files with 102 additions and 62 deletions

View File

@ -83,7 +83,8 @@ func search(u string) error {
}
history.Add(sv)
quickMessage("Searching...", true)
updateMainContent()
screen.ReflashScreen(true)
return nil
}
@ -112,17 +113,23 @@ func route_input(com *cmdparse.Command) error {
func toggle_bookmarks() {
bookmarks := screen.Windows[1]
main := screen.Windows[0]
if bookmarks.Show {
bookmarks.Show = false
screen.Activewindow = 0
main.Active = true
bookmarks.Active = false
} else {
bookmarks.Show = true
screen.Activewindow = 1
main.Active = false
bookmarks.Active = true
}
if screen.Activewindow == 0 {
screen.Activewindow = 1
} else {
screen.Activewindow = 0
}
screen.ReflashScreen(false)
}
func simple_command(a string) error {
@ -146,26 +153,28 @@ func simple_command(a string) error {
}
func go_to_url(u string) error {
quickMessage("Loading...", false)
v, err := gopher.Visit(u, options["openhttp"])
quickMessage("Loading...", false)
v, err := gopher.Visit(u, options["openhttp"])
if err != nil {
quickMessage("Loading...", true)
return err
}
quickMessage("Loading...", true)
if v.Address.Gophertype == "7" {
err := search(v.Address.Full)
if err != nil {
quickMessage("Loading...", true)
return err
}
quickMessage("Loading...", true)
if v.Address.Gophertype == "7" {
err := search(v.Address.Full)
if err != nil {
return err
}
} else if v.Address.IsBinary {
// TO DO: run this into the write to file method
return save_file_from_data(v)
} else {
history.Add(v)
}
return nil
} else if v.Address.IsBinary {
// TO DO: run this into the write to file method
return save_file_from_data(v)
} else {
history.Add(v)
}
updateMainContent()
screen.ReflashScreen(true)
return nil
}
func go_to_link(l string) error {
@ -198,6 +207,8 @@ func go_to_link(l string) error {
} else {
return fmt.Errorf("Invalid link id: %s", l)
}
updateMainContent()
screen.ReflashScreen(true)
return nil
}
@ -219,6 +230,7 @@ func do_link_command(action, target string) error {
err := settings.Bookmarks.Del(num)
screen.Windows[1].Content = settings.Bookmarks.List()
save_config()
screen.ReflashScreen(false)
return err
case "BOOKMARKS", "B":
if num > len(settings.Bookmarks.Links) - 1 {
@ -248,6 +260,7 @@ func do_command_as(action string, values []string) error {
}
screen.Windows[1].Content = settings.Bookmarks.List()
save_config()
screen.ReflashScreen(false)
return nil
case "WRITE", "W":
return save_file(values[0], strings.Join(values[1:], " "))
@ -282,6 +295,7 @@ func do_link_command_as(action, target string, values []string) error {
}
screen.Windows[1].Content = settings.Bookmarks.List()
save_config()
screen.ReflashScreen(false)
return nil
case "WRITE", "W":
return save_file(links[num - 1], strings.Join(values, " "))
@ -290,6 +304,12 @@ func do_link_command_as(action, target string, values []string) error {
return fmt.Errorf("This method has not been built")
}
func updateMainContent() {
screen.Windows[0].Content = history.Collection[history.Position].Content
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
}
func clearInput(incError bool) {
cui.MoveCursorTo(screen.Height - 1, 0)
cui.Clear("line")
@ -308,6 +328,7 @@ func quickMessage(msg string, clearMsg bool) {
}
}
func save_config() {
bkmrks := settings.Bookmarks.IniDump()
opts := "\n[SETTINGS]\n"
@ -320,6 +341,7 @@ func save_config() {
ioutil.WriteFile(userinfo.HomeDir + "/.bombadillo.ini", []byte(bkmrks+opts), 0644)
}
func load_config() {
file, err := os.Open(userinfo.HomeDir + "/.bombadillo.ini")
if err != nil {
@ -337,17 +359,34 @@ func load_config() {
}
}
func display_error(err error, redraw *bool) {
func toggleActiveWindow(){
if screen.Windows[1].Show {
if screen.Windows[0].Active {
screen.Windows[0].Active = false
screen.Windows[1].Active = true
screen.Activewindow = 1
} else {
screen.Windows[0].Active = true
screen.Windows[1].Active = false
screen.Activewindow = 0
}
screen.Windows[1].DrawWindow()
}
}
func display_error(err error) {
cui.MoveCursorTo(screen.Height, 0)
fmt.Print("\033[41m\033[37m", err, "\033[0m")
*redraw = false
}
func initClient() {
history.Position = -1
screen = cui.NewScreen()
cui.SetCharMode()
screen.AddWindow(2, 1, screen.Height - 2, screen.Width, false, false, true)
screen.Windows[0].Active = true
screen.AddMsgBar(1, " ((( Bombadillo ))) ", " A fun gopher client!", true)
bookmarksWidth := 40
if screen.Width < 40 {
@ -357,42 +396,40 @@ func initClient() {
load_config()
}
func main() {
defer cui.Exit()
initClient()
mainWindow := screen.Windows[0]
first_load := true
redrawScreen := true
for {
screen.ReflashScreen(redrawScreen)
if first_load {
first_load = false
err := go_home()
if err == nil {
mainWindow.Content = history.Collection[history.Position].Content
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
updateMainContent()
}
continue
}
redrawScreen = false
c := cui.Getch()
switch c {
case 'j', 'J':
screen.Windows[screen.Activewindow].ScrollDown()
screen.ReflashScreen(false)
case 'k', 'K':
screen.Windows[screen.Activewindow].ScrollUp()
screen.ReflashScreen(false)
case 'q', 'Q':
cui.Exit()
case 'b':
success := history.GoBack()
if success {
mainWindow.Scrollposition = 0
redrawScreen = true
updateMainContent()
screen.ReflashScreen(true)
}
case 'B':
toggle_bookmarks()
@ -400,35 +437,29 @@ func main() {
success := history.GoForward()
if success {
mainWindow.Scrollposition = 0
redrawScreen = true
updateMainContent()
screen.ReflashScreen(true)
}
case ':','-':
redrawScreen = true
case '\t':
toggleActiveWindow()
case ':',' ':
cui.MoveCursorTo(screen.Height - 1, 0)
entry := cui.GetLine()
// Clear entry line and error line
clearInput(true)
if entry == "" {
redrawScreen = false
continue
}
parser := cmdparse.NewParser(strings.NewReader(entry))
p, err := parser.Parse()
if err != nil {
display_error(err, &redrawScreen)
// Set screen to not reflash
display_error(err)
} else {
err := route_input(p)
if err != nil {
display_error(err, &redrawScreen)
} else {
mainWindow.Scrollposition = 0
display_error(err)
}
}
}
if history.Position >= 0 {
mainWindow.Content = history.Collection[history.Position].Content
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
}
}
}

View File

@ -10,16 +10,21 @@ import (
)
var shapes = map[string]string{
"wall": "",
"ceiling": "",
"wall": "",
"ceiling": "",
"tl": "┌",
"tr": "┐",
"bl": "└",
"br": "┘",
"scroll-thumb": "▉",
"scroll-track": "░",
"awall": "║",
"aceiling": "═",
"atl": "╔",
"atr": "╗",
"abl": "╚",
"abr": "╝",
}
func drawShape(shape string) {
if val, ok := shapes[shape]; ok {
fmt.Printf("%s", val)

View File

@ -51,10 +51,9 @@ func (s Screen) DrawAllWindows() {
// Clear removes all content from the interior of the screen
func (s Screen) Clear() {
fill := strings.Repeat(" ", s.Width)
for i := 0; i <= s.Height; i++ {
MoveCursorTo(i, 0)
fmt.Print(fill)
Clear("line")
}
}

View File

@ -33,18 +33,22 @@ func (w *Window) DrawWindow() {
}
func (w *Window) DrawBox(){
moveThenDrawShape(w.Box.row1, w.Box.col1, "tl")
moveThenDrawShape(w.Box.row1, w.Box.col2, "tr")
moveThenDrawShape(w.Box.row2, w.Box.col1, "bl")
moveThenDrawShape(w.Box.row2, w.Box.col2, "br")
lead := ""
if w.Active {
lead = "a"
}
moveThenDrawShape(w.Box.row1, w.Box.col1, lead + "tl")
moveThenDrawShape(w.Box.row1, w.Box.col2, lead + "tr")
moveThenDrawShape(w.Box.row2, w.Box.col1, lead + "bl")
moveThenDrawShape(w.Box.row2, w.Box.col2, lead + "br")
for i := w.Box.col1 + 1; i < w.Box.col2; i++ {
moveThenDrawShape(w.Box.row1, i, "ceiling")
moveThenDrawShape(w.Box.row2, i, "ceiling")
moveThenDrawShape(w.Box.row1, i, lead + "ceiling")
moveThenDrawShape(w.Box.row2, i, lead + "ceiling")
}
for i:= w.Box.row1 + 1; i < w.Box.row2; i++ {
moveThenDrawShape(i, w.Box.col1, "wall")
moveThenDrawShape(i, w.Box.col2, "wall")
moveThenDrawShape(i, w.Box.col1, lead + "wall")
moveThenDrawShape(i, w.Box.col2, lead + "wall")
}
}

View File

@ -1,10 +1,9 @@
TODO
- Add built in help system: SIMPLE :help, DO :help action
- Add styles/color support
- Add comments/documentation for all items
- Add code comments/documentation for all items
- Make sure html links using the URL convention work correctly
- Add "Search" command. ":search thing1 thing2" that uses search as set in config
- Verify that all gophertypes work correctly
Control keys/input:
@ -12,7 +11,7 @@ q quit
j scrolldown
k scrollup
f toggle showing favorites as subwindow
r refresh current page data (re-request)
TODO - r refresh current page data (re-request)
GO
:# go to link num
@ -22,6 +21,8 @@ SIMPLE
:quit quit
:home visit home
:bookmarks toogle bookmarks window
:search
:help
DOLINK
:delete # delete bookmark with num