Skip to content

Commit

Permalink
Fix terminal style differences based on colour scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Sep 12, 2020
1 parent 6fa4988 commit ca3fcd8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 17 deletions.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# min

A Gemini browser for your terminal.

<img src="demo.gif"/>

## Features

* Vim style keyboard navigation
* Easy to understand implementation - one file, 1500 lines
* Client certificate support
* History (saved to TSV file)
* Bookmarks (saved to TSV file)

## Help

## Navigation

```
n/Tab Next link / option
Ctrl-O/Shift+Tab Previous link / option
Enter Navigate to selected link
H Navigate backwards in history
L Navigate forwards in history
Esc Exit
```

### Features

```
b Toggle bookmark
B View bookmarks
Ctrl-H View history
? View help
```

### Scrolling

```
g Scroll to top of document
G Scroll to end of document
←/h Scroll left
↓/j Scroll down
↑/k Scroll up
→/l Scroll right
Home Scroll home horizontally
End Scroll end horizontally
Ctrl-U Scroll up half a screen
Ctrl-D Scroll down half a screen
```

## Configuration

### config.ini

* Stored at $HOME/.min/config.ini
* Consists of key/value pairs (e.g. "width=80")
* Contains previously accepted server certificates
* Contains links to client certificates, stored in the same directory

## history.tsv

* Stores previously visited URLs

## boomarks.tsv

* Stores bookmarks
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ github.com/natefinch/atomic v0.0.0-20200526193002-18c0533a5b09/go.mod h1:1rLVY/D
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200817155316-9781c653f443 h1:X18bCaipMcoJGm27Nv7zr4XYPKGUy92GtqboKC2Hxaw=
golang.org/x/sys v0.0.0-20200817155316-9781c653f443/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
34 changes: 17 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func readLines(fn string) (lines []string, err error) {
return
}

var defaultStyle = tcell.StyleDefault.
Foreground(tcell.ColorWhite).
Background(tcell.ColorBlack)

func main() {
// Configure the context to handle SIGINT.
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -222,9 +226,7 @@ func main() {
os.Exit(1)
}
defer s.Fini()
s.SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorWhite).
Background(tcell.ColorBlack))
s.SetStyle(defaultStyle)
state.Screen = s
Run(ctx, state)
}
Expand Down Expand Up @@ -553,7 +555,7 @@ func NewText(s tcell.Screen, text string) *Text {
Screen: s,
X: 0,
Y: 0,
Style: tcell.StyleDefault,
Style: defaultStyle,
Text: text,
}
}
Expand Down Expand Up @@ -622,7 +624,7 @@ func NewOptions(s tcell.Screen, msg string, opts ...string) *Options {
}
return &Options{
Screen: s,
Style: tcell.StyleDefault,
Style: defaultStyle,
Message: msg,
Options: opts,
CancelIndex: cancelIndex,
Expand All @@ -645,9 +647,9 @@ func (o *Options) Draw() {
t := NewText(o.Screen, o.Message)
_, y := t.Draw()
for i, oo := range o.Options {
style := tcell.StyleDefault
style := defaultStyle
if i == o.ActiveIndex {
style = tcell.StyleDefault.Background(tcell.ColorLightGray)
style = defaultStyle.Background(tcell.ColorLightGray)
}
NewText(o.Screen, fmt.Sprintf("[ %s ]", oo)).WithOffset(1, i+y+2).WithStyle(style).Draw()
}
Expand Down Expand Up @@ -780,7 +782,7 @@ func (l PreformattedTextLine) Draw(to tcell.Screen, atX, atY int, highlighted bo
c = ' '
w = 1
}
to.SetContent(atX, atY, c, comb, tcell.StyleDefault)
to.SetContent(atX, atY, c, comb, defaultStyle)
atX += w
}
return atX, atY
Expand All @@ -806,7 +808,7 @@ func (l LinkLine) URL(relativeTo *url.URL) (u *url.URL, err error) {
}

func (l LinkLine) Draw(to tcell.Screen, atX, atY int, highlighted bool) (x, y int) {
ls := tcell.StyleDefault.Foreground(tcell.ColorDarkCyan)
ls := defaultStyle.Foreground(tcell.ColorDarkCyan)
if highlighted {
ls = ls.Background(tcell.ColorWhite).Foreground(tcell.ColorDarkCyan)
}
Expand All @@ -819,7 +821,7 @@ type HeadingLine struct {
}

func (l HeadingLine) Draw(to tcell.Screen, atX, atY int, highlighted bool) (x, y int) {
return NewText(to, l.Text).WithOffset(atX, atY).WithMaxWidth(l.MaxWidth).WithStyle(tcell.StyleDefault.Foreground(tcell.ColorGreen)).Draw()
return NewText(to, l.Text).WithOffset(atX, atY).WithMaxWidth(l.MaxWidth).WithStyle(defaultStyle.Foreground(tcell.ColorGreen)).Draw()
}

type UnorderedListItemLine struct {
Expand All @@ -837,7 +839,7 @@ type QuoteLine struct {
}

func (l QuoteLine) Draw(to tcell.Screen, atX, atY int, highlighted bool) (x, y int) {
return NewText(to, l.Text).WithOffset(atX+2, atY).WithMaxWidth(l.MaxWidth).WithStyle(tcell.StyleDefault.Foreground(tcell.ColorLightGrey)).Draw()
return NewText(to, l.Text).WithOffset(atX+2, atY).WithMaxWidth(l.MaxWidth).WithStyle(defaultStyle.Foreground(tcell.ColorLightGrey)).Draw()
}

func NewBrowser(s tcell.Screen, w int, u *url.URL, resp *gemini.Response) (b *Browser, err error) {
Expand Down Expand Up @@ -1282,7 +1284,7 @@ func NewInput(s tcell.Screen, msg, text string) *Input {
Screen: s,
X: 0,
Y: 0,
Style: tcell.StyleDefault,
Style: defaultStyle,
Message: msg,
Text: text,
CursorIndex: len(text),
Expand All @@ -1304,25 +1306,23 @@ func (o *Input) Draw() {
o.Screen.Clear()
_, y := NewText(o.Screen, o.Message).WithOffset(o.X, o.Y).WithStyle(o.Style).Draw()

defaultStyle := tcell.StyleDefault
activeStyle := tcell.StyleDefault.Background(tcell.ColorLightGray)

textStyle := defaultStyle
if o.ActiveIndex == 0 {
NewText(o.Screen, ">").WithOffset(o.X, o.Y+y+2).WithStyle(defaultStyle).Draw()
}
NewText(o.Screen, o.Text).WithOffset(o.X+2, o.Y+y+2).WithStyle(textStyle).Draw()
NewText(o.Screen, o.Text).WithOffset(o.X+2, o.Y+y+2).WithStyle(defaultStyle).Draw()
if o.ActiveIndex == 0 {
o.Screen.ShowCursor(o.X+2+o.CursorIndex, o.Y+y+2)
} else {
o.Screen.HideCursor()
}

activeStyle := defaultStyle.Background(tcell.ColorLightGray)
okStyle := defaultStyle
if o.ActiveIndex == 1 {
okStyle = activeStyle
}
NewText(o.Screen, "[ OK ]").WithOffset(1, o.Y+y+4).WithStyle(okStyle).Draw()

cancelStyle := defaultStyle
if o.ActiveIndex == 2 {
cancelStyle = activeStyle
Expand Down

0 comments on commit ca3fcd8

Please sign in to comment.