Added focus shifting between windows redid how draws work
This commit is contained in:
parent
e0083ae444
commit
88898c5b4a
117
bombadillo.go
117
bombadillo.go
|
@ -83,7 +83,8 @@ func search(u string) error {
|
||||||
}
|
}
|
||||||
history.Add(sv)
|
history.Add(sv)
|
||||||
quickMessage("Searching...", true)
|
quickMessage("Searching...", true)
|
||||||
|
updateMainContent()
|
||||||
|
screen.ReflashScreen(true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,17 +113,23 @@ func route_input(com *cmdparse.Command) error {
|
||||||
|
|
||||||
func toggle_bookmarks() {
|
func toggle_bookmarks() {
|
||||||
bookmarks := screen.Windows[1]
|
bookmarks := screen.Windows[1]
|
||||||
|
main := screen.Windows[0]
|
||||||
if bookmarks.Show {
|
if bookmarks.Show {
|
||||||
bookmarks.Show = false
|
bookmarks.Show = false
|
||||||
|
screen.Activewindow = 0
|
||||||
|
main.Active = true
|
||||||
|
bookmarks.Active = false
|
||||||
} else {
|
} else {
|
||||||
bookmarks.Show = true
|
bookmarks.Show = true
|
||||||
|
screen.Activewindow = 1
|
||||||
|
main.Active = false
|
||||||
|
bookmarks.Active = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if screen.Activewindow == 0 {
|
if screen.Activewindow == 0 {
|
||||||
screen.Activewindow = 1
|
|
||||||
} else {
|
} else {
|
||||||
screen.Activewindow = 0
|
|
||||||
}
|
}
|
||||||
|
screen.ReflashScreen(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func simple_command(a string) error {
|
func simple_command(a string) error {
|
||||||
|
@ -146,26 +153,28 @@ func simple_command(a string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func go_to_url(u string) error {
|
func go_to_url(u string) error {
|
||||||
quickMessage("Loading...", false)
|
quickMessage("Loading...", false)
|
||||||
v, err := gopher.Visit(u, options["openhttp"])
|
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 {
|
if err != nil {
|
||||||
quickMessage("Loading...", true)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
quickMessage("Loading...", true)
|
} else if v.Address.IsBinary {
|
||||||
|
// TO DO: run this into the write to file method
|
||||||
if v.Address.Gophertype == "7" {
|
return save_file_from_data(v)
|
||||||
err := search(v.Address.Full)
|
} else {
|
||||||
if err != nil {
|
history.Add(v)
|
||||||
return err
|
}
|
||||||
}
|
updateMainContent()
|
||||||
} else if v.Address.IsBinary {
|
screen.ReflashScreen(true)
|
||||||
// TO DO: run this into the write to file method
|
return nil
|
||||||
return save_file_from_data(v)
|
|
||||||
} else {
|
|
||||||
history.Add(v)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func go_to_link(l string) error {
|
func go_to_link(l string) error {
|
||||||
|
@ -198,6 +207,8 @@ func go_to_link(l string) error {
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("Invalid link id: %s", l)
|
return fmt.Errorf("Invalid link id: %s", l)
|
||||||
}
|
}
|
||||||
|
updateMainContent()
|
||||||
|
screen.ReflashScreen(true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,6 +230,7 @@ func do_link_command(action, target string) error {
|
||||||
err := settings.Bookmarks.Del(num)
|
err := settings.Bookmarks.Del(num)
|
||||||
screen.Windows[1].Content = settings.Bookmarks.List()
|
screen.Windows[1].Content = settings.Bookmarks.List()
|
||||||
save_config()
|
save_config()
|
||||||
|
screen.ReflashScreen(false)
|
||||||
return err
|
return err
|
||||||
case "BOOKMARKS", "B":
|
case "BOOKMARKS", "B":
|
||||||
if num > len(settings.Bookmarks.Links) - 1 {
|
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()
|
screen.Windows[1].Content = settings.Bookmarks.List()
|
||||||
save_config()
|
save_config()
|
||||||
|
screen.ReflashScreen(false)
|
||||||
return nil
|
return nil
|
||||||
case "WRITE", "W":
|
case "WRITE", "W":
|
||||||
return save_file(values[0], strings.Join(values[1:], " "))
|
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()
|
screen.Windows[1].Content = settings.Bookmarks.List()
|
||||||
save_config()
|
save_config()
|
||||||
|
screen.ReflashScreen(false)
|
||||||
return nil
|
return nil
|
||||||
case "WRITE", "W":
|
case "WRITE", "W":
|
||||||
return save_file(links[num - 1], strings.Join(values, " "))
|
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")
|
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) {
|
func clearInput(incError bool) {
|
||||||
cui.MoveCursorTo(screen.Height - 1, 0)
|
cui.MoveCursorTo(screen.Height - 1, 0)
|
||||||
cui.Clear("line")
|
cui.Clear("line")
|
||||||
|
@ -308,6 +328,7 @@ func quickMessage(msg string, clearMsg bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func save_config() {
|
func save_config() {
|
||||||
bkmrks := settings.Bookmarks.IniDump()
|
bkmrks := settings.Bookmarks.IniDump()
|
||||||
opts := "\n[SETTINGS]\n"
|
opts := "\n[SETTINGS]\n"
|
||||||
|
@ -320,6 +341,7 @@ func save_config() {
|
||||||
ioutil.WriteFile(userinfo.HomeDir + "/.bombadillo.ini", []byte(bkmrks+opts), 0644)
|
ioutil.WriteFile(userinfo.HomeDir + "/.bombadillo.ini", []byte(bkmrks+opts), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func load_config() {
|
func load_config() {
|
||||||
file, err := os.Open(userinfo.HomeDir + "/.bombadillo.ini")
|
file, err := os.Open(userinfo.HomeDir + "/.bombadillo.ini")
|
||||||
if err != nil {
|
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)
|
cui.MoveCursorTo(screen.Height, 0)
|
||||||
fmt.Print("\033[41m\033[37m", err, "\033[0m")
|
fmt.Print("\033[41m\033[37m", err, "\033[0m")
|
||||||
*redraw = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func initClient() {
|
func initClient() {
|
||||||
history.Position = -1
|
history.Position = -1
|
||||||
screen = cui.NewScreen()
|
screen = cui.NewScreen()
|
||||||
cui.SetCharMode()
|
cui.SetCharMode()
|
||||||
screen.AddWindow(2, 1, screen.Height - 2, screen.Width, false, false, true)
|
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)
|
screen.AddMsgBar(1, " ((( Bombadillo ))) ", " A fun gopher client!", true)
|
||||||
bookmarksWidth := 40
|
bookmarksWidth := 40
|
||||||
if screen.Width < 40 {
|
if screen.Width < 40 {
|
||||||
|
@ -357,42 +396,40 @@ func initClient() {
|
||||||
load_config()
|
load_config()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defer cui.Exit()
|
defer cui.Exit()
|
||||||
initClient()
|
initClient()
|
||||||
mainWindow := screen.Windows[0]
|
mainWindow := screen.Windows[0]
|
||||||
first_load := true
|
first_load := true
|
||||||
redrawScreen := true
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
screen.ReflashScreen(redrawScreen)
|
|
||||||
|
|
||||||
if first_load {
|
if first_load {
|
||||||
first_load = false
|
first_load = false
|
||||||
err := go_home()
|
err := go_home()
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mainWindow.Content = history.Collection[history.Position].Content
|
updateMainContent()
|
||||||
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
redrawScreen = false
|
|
||||||
|
|
||||||
c := cui.Getch()
|
c := cui.Getch()
|
||||||
switch c {
|
switch c {
|
||||||
case 'j', 'J':
|
case 'j', 'J':
|
||||||
screen.Windows[screen.Activewindow].ScrollDown()
|
screen.Windows[screen.Activewindow].ScrollDown()
|
||||||
|
screen.ReflashScreen(false)
|
||||||
case 'k', 'K':
|
case 'k', 'K':
|
||||||
screen.Windows[screen.Activewindow].ScrollUp()
|
screen.Windows[screen.Activewindow].ScrollUp()
|
||||||
|
screen.ReflashScreen(false)
|
||||||
case 'q', 'Q':
|
case 'q', 'Q':
|
||||||
cui.Exit()
|
cui.Exit()
|
||||||
case 'b':
|
case 'b':
|
||||||
success := history.GoBack()
|
success := history.GoBack()
|
||||||
if success {
|
if success {
|
||||||
mainWindow.Scrollposition = 0
|
mainWindow.Scrollposition = 0
|
||||||
redrawScreen = true
|
updateMainContent()
|
||||||
|
screen.ReflashScreen(true)
|
||||||
}
|
}
|
||||||
case 'B':
|
case 'B':
|
||||||
toggle_bookmarks()
|
toggle_bookmarks()
|
||||||
|
@ -400,35 +437,29 @@ func main() {
|
||||||
success := history.GoForward()
|
success := history.GoForward()
|
||||||
if success {
|
if success {
|
||||||
mainWindow.Scrollposition = 0
|
mainWindow.Scrollposition = 0
|
||||||
redrawScreen = true
|
updateMainContent()
|
||||||
|
screen.ReflashScreen(true)
|
||||||
}
|
}
|
||||||
case ':','-':
|
case '\t':
|
||||||
redrawScreen = true
|
toggleActiveWindow()
|
||||||
|
case ':',' ':
|
||||||
cui.MoveCursorTo(screen.Height - 1, 0)
|
cui.MoveCursorTo(screen.Height - 1, 0)
|
||||||
entry := cui.GetLine()
|
entry := cui.GetLine()
|
||||||
// Clear entry line and error line
|
// Clear entry line and error line
|
||||||
clearInput(true)
|
clearInput(true)
|
||||||
if entry == "" {
|
if entry == "" {
|
||||||
redrawScreen = false
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parser := cmdparse.NewParser(strings.NewReader(entry))
|
parser := cmdparse.NewParser(strings.NewReader(entry))
|
||||||
p, err := parser.Parse()
|
p, err := parser.Parse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
display_error(err, &redrawScreen)
|
display_error(err)
|
||||||
// Set screen to not reflash
|
|
||||||
} else {
|
} else {
|
||||||
err := route_input(p)
|
err := route_input(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
display_error(err, &redrawScreen)
|
display_error(err)
|
||||||
} else {
|
|
||||||
mainWindow.Scrollposition = 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if history.Position >= 0 {
|
|
||||||
mainWindow.Content = history.Collection[history.Position].Content
|
|
||||||
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
cui/cui.go
13
cui/cui.go
|
@ -10,16 +10,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var shapes = map[string]string{
|
var shapes = map[string]string{
|
||||||
"wall": "│",
|
"wall": "╵",
|
||||||
"ceiling": "─",
|
"ceiling": "╴",
|
||||||
"tl": "┌",
|
"tl": "┌",
|
||||||
"tr": "┐",
|
"tr": "┐",
|
||||||
"bl": "└",
|
"bl": "└",
|
||||||
"br": "┘",
|
"br": "┘",
|
||||||
"scroll-thumb": "▉",
|
"awall": "║",
|
||||||
"scroll-track": "░",
|
"aceiling": "═",
|
||||||
|
"atl": "╔",
|
||||||
|
"atr": "╗",
|
||||||
|
"abl": "╚",
|
||||||
|
"abr": "╝",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func drawShape(shape string) {
|
func drawShape(shape string) {
|
||||||
if val, ok := shapes[shape]; ok {
|
if val, ok := shapes[shape]; ok {
|
||||||
fmt.Printf("%s", val)
|
fmt.Printf("%s", val)
|
||||||
|
|
|
@ -51,10 +51,9 @@ func (s Screen) DrawAllWindows() {
|
||||||
|
|
||||||
// Clear removes all content from the interior of the screen
|
// Clear removes all content from the interior of the screen
|
||||||
func (s Screen) Clear() {
|
func (s Screen) Clear() {
|
||||||
fill := strings.Repeat(" ", s.Width)
|
|
||||||
for i := 0; i <= s.Height; i++ {
|
for i := 0; i <= s.Height; i++ {
|
||||||
MoveCursorTo(i, 0)
|
MoveCursorTo(i, 0)
|
||||||
fmt.Print(fill)
|
Clear("line")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,18 +33,22 @@ func (w *Window) DrawWindow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) DrawBox(){
|
func (w *Window) DrawBox(){
|
||||||
moveThenDrawShape(w.Box.row1, w.Box.col1, "tl")
|
lead := ""
|
||||||
moveThenDrawShape(w.Box.row1, w.Box.col2, "tr")
|
if w.Active {
|
||||||
moveThenDrawShape(w.Box.row2, w.Box.col1, "bl")
|
lead = "a"
|
||||||
moveThenDrawShape(w.Box.row2, w.Box.col2, "br")
|
}
|
||||||
|
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++ {
|
for i := w.Box.col1 + 1; i < w.Box.col2; i++ {
|
||||||
moveThenDrawShape(w.Box.row1, i, "ceiling")
|
moveThenDrawShape(w.Box.row1, i, lead + "ceiling")
|
||||||
moveThenDrawShape(w.Box.row2, i, "ceiling")
|
moveThenDrawShape(w.Box.row2, i, lead + "ceiling")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i:= w.Box.row1 + 1; i < w.Box.row2; i++ {
|
for i:= w.Box.row1 + 1; i < w.Box.row2; i++ {
|
||||||
moveThenDrawShape(i, w.Box.col1, "wall")
|
moveThenDrawShape(i, w.Box.col1, lead + "wall")
|
||||||
moveThenDrawShape(i, w.Box.col2, "wall")
|
moveThenDrawShape(i, w.Box.col2, lead + "wall")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
notes.md
11
notes.md
|
@ -1,10 +1,9 @@
|
||||||
TODO
|
TODO
|
||||||
- Add built in help system: SIMPLE :help, DO :help action
|
|
||||||
- Add styles/color support
|
- 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
|
- 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:
|
Control keys/input:
|
||||||
|
|
||||||
|
@ -12,7 +11,7 @@ q quit
|
||||||
j scrolldown
|
j scrolldown
|
||||||
k scrollup
|
k scrollup
|
||||||
f toggle showing favorites as subwindow
|
f toggle showing favorites as subwindow
|
||||||
r refresh current page data (re-request)
|
TODO - r refresh current page data (re-request)
|
||||||
|
|
||||||
GO
|
GO
|
||||||
:# go to link num
|
:# go to link num
|
||||||
|
@ -22,6 +21,8 @@ SIMPLE
|
||||||
:quit quit
|
:quit quit
|
||||||
:home visit home
|
:home visit home
|
||||||
:bookmarks toogle bookmarks window
|
:bookmarks toogle bookmarks window
|
||||||
|
:search
|
||||||
|
:help
|
||||||
|
|
||||||
DOLINK
|
DOLINK
|
||||||
:delete # delete bookmark with num
|
:delete # delete bookmark with num
|
||||||
|
|
Loading…
Reference in New Issue