Skip to content

Commit

Permalink
Add borderless flag and config option
Browse files Browse the repository at this point in the history
Closes #10.
  • Loading branch information
FIGBERT committed Aug 15, 2022
1 parent ebc4db3 commit 4b594b8
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 32 deletions.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type config struct {

Log bool
RequireEncryption bool `toml:"require-encryption"`
Borderless bool

Theme toml.Primitive
Keys full.CustomKeyMap
Expand Down
10 changes: 5 additions & 5 deletions full/add_torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (m addTorrent) Init() tea.Cmd {
func (m addTorrent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width - styles.BorderWindow.GetHorizontalBorderSize()
m.height = msg.Height - styles.BorderWindow.GetHorizontalBorderSize()
m.width = msg.Width - styles.Fullscreen.GetHorizontalBorderSize()
m.height = msg.Height - styles.Fullscreen.GetHorizontalBorderSize()

updated, _ := m.main.Update(msg)
if mdl, ok := updated.(model); ok {
Expand Down Expand Up @@ -95,13 +95,13 @@ func (m addTorrent) View() string {
fullscreen := gloss.NewStyle().
Width(m.width).
Height(m.height).
Inherit(styles.BorderWindow)
Inherit(styles.Fullscreen)

var body strings.Builder
body.WriteString("Add Torrent\n")
body.WriteString(styles.BorderWindow.Render(m.torrent.View()))
body.WriteString(styles.Window.Render(m.torrent.View()))
body.WriteString("\n\nSave Directory (Optional)\n")
body.WriteString(styles.BorderWindow.Render(m.saveDir.View()))
body.WriteString(styles.Window.Render(m.saveDir.View()))

help := m.help.View(addTorrentKeys)
height := m.height - gloss.Height(help) - 1
Expand Down
8 changes: 4 additions & 4 deletions full/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func (m errorScreen) Init() tea.Cmd {
func (m errorScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width - styles.BorderWindow.GetHorizontalBorderSize()
m.height = msg.Height - styles.BorderWindow.GetHorizontalBorderSize()
m.width = msg.Width - styles.Fullscreen.GetHorizontalBorderSize()
m.height = msg.Height - styles.Fullscreen.GetHorizontalBorderSize()

updated, _ := m.main.Update(msg)
if mdl, ok := updated.(model); ok {
Expand Down Expand Up @@ -56,13 +56,13 @@ func (m errorScreen) View() string {
fullscreen := gloss.NewStyle().
Width(m.width).
Height(m.height).
Inherit(styles.BorderWindow).
Inherit(styles.Fullscreen).
BorderForeground(m.theme.Error)
popupWindow := gloss.NewStyle().
Width(popupWidth).
Height(popupHeight).
Padding(0, padding).
Inherit(styles.BorderWindow).
Inherit(styles.Window).
BorderForeground(m.theme.Error)
header := gloss.NewStyle().Bold(true)

Expand Down
2 changes: 1 addition & 1 deletion full/file_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func fileView(files *[]*torrent.File, w *int, h *int) string {
box := gloss.NewStyle().
Width(width).
Height(height).
Inherit(styles.BorderWindow).
Inherit(styles.Window).
UnsetAlign()
if len(*files) < height {
box.UnsetHeight()
Expand Down
8 changes: 4 additions & 4 deletions full/port_startup_failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (m portStartupFailure) Init() tea.Cmd {
func (m portStartupFailure) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width - styles.BorderWindow.GetHorizontalBorderSize()
m.height = msg.Height - styles.BorderWindow.GetHorizontalBorderSize()
m.width = msg.Width - styles.Fullscreen.GetHorizontalBorderSize()
m.height = msg.Height - styles.Fullscreen.GetHorizontalBorderSize()

updated, _ := m.main.Update(msg)
if mdl, ok := updated.(model); ok {
Expand Down Expand Up @@ -81,12 +81,12 @@ func (m portStartupFailure) View() string {
fullscreen := gloss.NewStyle().
Width(m.width).
Height(m.height).
Inherit(styles.BorderWindow)
Inherit(styles.Fullscreen)

var body strings.Builder
body.WriteString(styles.Bold.Render("Port Binding Failure"))
body.WriteString("\nplease provide an unused port number for the client to bind with\n\n")
body.WriteString(styles.BorderWindow.Render(m.input.View()))
body.WriteString(styles.Window.Render(m.input.View()))

return fullscreen.Render(
gloss.Place(
Expand Down
6 changes: 3 additions & 3 deletions full/torrent_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (m torrentDetails) Init() tea.Cmd {
func (m torrentDetails) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width - styles.BorderWindow.GetHorizontalBorderSize()
m.height = msg.Height - styles.BorderWindow.GetHorizontalBorderSize()
m.width = msg.Width - styles.Fullscreen.GetHorizontalBorderSize()
m.height = msg.Height - styles.Fullscreen.GetHorizontalBorderSize()

updated, _ := m.main.Update(msg)
if mdl, ok := updated.(model); ok {
Expand All @@ -60,7 +60,7 @@ func (m torrentDetails) View() string {
fullscreen := gloss.NewStyle().
Width(m.width).
Height(m.height).
Inherit(styles.BorderWindow)
Inherit(styles.Fullscreen)

t := m.item.Self

Expand Down
4 changes: 2 additions & 2 deletions full/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func reportError(err error) tea.Cmd {
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg: // Change to fit new window size
width := msg.Width - styles.BorderWindow.GetHorizontalBorderSize()
height := msg.Height - styles.BorderWindow.GetHorizontalBorderSize()
width := msg.Width - styles.Fullscreen.GetHorizontalBorderSize()
height := msg.Height - styles.Fullscreen.GetHorizontalBorderSize()

m.width = width
m.help.Width = width
Expand Down
2 changes: 1 addition & 1 deletion full/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (m model) View() string {
fullscreen := gloss.NewStyle().
Width(m.width).
Height(m.height).
Inherit(styles.BorderWindow)
Inherit(styles.Fullscreen)

var content string
if torrents := m.client.Torrents(); len(torrents) > 0 {
Expand Down
9 changes: 5 additions & 4 deletions internal/styles/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import gloss "github.com/charmbracelet/lipgloss"
var (
Bold = gloss.NewStyle().Bold(true)

Border = gloss.RoundedBorder()
BorderWindow = gloss.NewStyle().
Align(gloss.Center).
BorderStyle(Border)
Border = gloss.RoundedBorder()
Window = gloss.NewStyle().
Align(gloss.Center).
BorderStyle(Border)
Fullscreen = Window.Copy()
)
27 changes: 19 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ var (

func main() {
var (
download = flag.StringP("download", "d", xdg.UserDirs.Download, "Set the default directory for downloaded torrents.")
port = flag.UintP("port", "p", 42069, "Set the port number to which the client will bind.")
theme = flag.StringP("theme", "t", "default", "Set the color theme that the client will use.")
logging = flag.BoolP("log", "l", false, "Enable client logging.")
encrypt = flag.BoolP("encrypt", "e", false, "Ignore unencrypted peers.")
help = flag.BoolP("help", "h", false, "Print this help message.")
vrsn = flag.BoolP("version", "v", false, "Print version information.")
download = flag.StringP("download", "d", xdg.UserDirs.Download, "Set the default directory for downloaded torrents.")
port = flag.UintP("port", "p", 42069, "Set the port number to which the client will bind.")
theme = flag.StringP("theme", "t", "default", "Set the color theme that the client will use.")
logging = flag.BoolP("log", "l", false, "Enable client logging.")
encrypt = flag.BoolP("encrypt", "e", false, "Ignore unencrypted peers.")
borderless = flag.BoolP("borderless", "b", false, "Do not render an outer border.")
help = flag.BoolP("help", "h", false, "Print this help message.")
vrsn = flag.BoolP("version", "v", false, "Print version information.")
)
flag.Parse()
args := flag.Args()
Expand All @@ -59,6 +60,8 @@ func main() {
menu.WriteString("\n Enable client logging. [dir: " + green.Render("$XDG_STATE_HOME/mabel") + "]")
menu.WriteString("\n " + green.Render("-e") + ", " + green.Render("--encrypt"))
menu.WriteString("\n Ignore unencrypted peers.")
menu.WriteString("\n " + green.Render("-b") + ", " + green.Render("--borderless"))
menu.WriteString("\n Do not render an outer border.")
menu.WriteString("\n " + green.Render("-h") + ", " + green.Render("--help"))
menu.WriteString("\n Print this help message.")
menu.WriteString("\n " + green.Render("-v") + ", " + green.Render("--version"))
Expand Down Expand Up @@ -119,6 +122,7 @@ func main() {
themeFlag := flag.Lookup("theme")
loggingFlag := flag.Lookup("log")
encryptFlag := flag.Lookup("encrypt")
borderlessFlag := flag.Lookup("borderless")
thm := conf.getTheme()
key := conf.Keys

Expand All @@ -134,11 +138,18 @@ func main() {
if !encryptFlag.Changed {
flag.Set("encrypt", fmt.Sprint(conf.RequireEncryption))
}
if !borderlessFlag.Changed {
flag.Set("borderless", fmt.Sprint(conf.Borderless))
}
if themeFlag.Changed {
thm = styles.StringToTheme(theme)
}

styles.BorderWindow = styles.BorderWindow.BorderForeground(thm.Primary)
if *borderless {
styles.Fullscreen = styles.Fullscreen.BorderStyle(gloss.HiddenBorder())
}
styles.Window = styles.Window.BorderForeground(thm.Primary)
styles.Fullscreen = styles.Fullscreen.BorderForeground(thm.Primary)

if flag.NArg() == 1 {
mini.Execute(&args[0], download, port, logging, encrypt, thm)
Expand Down

0 comments on commit 4b594b8

Please sign in to comment.