Renames a cui function to be more appropriate and adds command line flag for version number

This commit is contained in:
sloumdrone 2019-09-20 09:18:16 -07:00
parent 8c42748432
commit 19f210f243
2 changed files with 19 additions and 7 deletions

View File

@ -65,8 +65,8 @@ func Exit() {
fmt.Print("\n") fmt.Print("\n")
fmt.Print("\033[?25h") fmt.Print("\033[?25h")
HandleAlternateScreen("smam") Tput("smam") // turn off line wrap
HandleAlternateScreen("rmcup") Tput("rmcup") // use alternate screen
os.Exit(0) os.Exit(0)
} }
@ -178,7 +178,7 @@ func SetLineMode() {
} }
} }
func HandleAlternateScreen(opt string) { func Tput(opt string) {
cmd := exec.Command("tput", opt) cmd := exec.Command("tput", opt)
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout

20
main.go
View File

@ -7,6 +7,8 @@ package main
// the terms of said license with said license file included. // the terms of said license with said license file included.
import ( import (
"flag"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"strings" "strings"
@ -15,6 +17,8 @@ import (
"tildegit.org/sloum/bombadillo/cui" "tildegit.org/sloum/bombadillo/cui"
) )
const version = "2.0.0"
var bombadillo *client var bombadillo *client
var helplocation string = "gopher://colorfield.space:70/1/bombadillo-info" var helplocation string = "gopher://colorfield.space:70/1/bombadillo-info"
var settings config.Config var settings config.Config
@ -94,8 +98,16 @@ func initClient() error {
} }
func main() { func main() {
cui.HandleAlternateScreen("rmam") getVersion := flag.Bool("v", false, "See version number")
cui.HandleAlternateScreen("smcup") flag.Parse()
if *getVersion {
fmt.Printf("Bombadillo v%s\n", version)
os.Exit(0)
}
args := flag.Args()
cui.Tput("rmam") // turn off line wrapping
cui.Tput("smcup") // use alternate screen
defer cui.Exit() defer cui.Exit()
err := initClient() err := initClient()
if err != nil { if err != nil {
@ -106,11 +118,11 @@ func main() {
// Start polling for terminal size changes // Start polling for terminal size changes
go bombadillo.GetSize() go bombadillo.GetSize()
if len(os.Args) > 1 { if len(args) > 0 {
// If a url was passed, move it down the line // If a url was passed, move it down the line
// Goroutine so keypresses can be made during // Goroutine so keypresses can be made during
// page load // page load
bombadillo.Visit(os.Args[1]) bombadillo.Visit(args[0])
} else { } else {
// Otherwise, load the homeurl // Otherwise, load the homeurl
// Goroutine so keypresses can be made during // Goroutine so keypresses can be made during