Skip to content

Commit

Permalink
Merge pull request #29 from zMoooooritz/misc
Browse files Browse the repository at this point in the history
Miscellaneous changes and improvements
  • Loading branch information
zMoooooritz authored Nov 15, 2023
2 parents c95fa29 + d75ed2a commit 75d878c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
4 changes: 4 additions & 0 deletions configs/example_config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# Global settings for the application
Settings:
HideHelpOnStartup: true

# Configuration of how to open specific resources
# Via the args it is possible to provide flags to the application
# the arg $ will be replaced by the url of the resource
Expand Down
25 changes: 20 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import (
)

type Configuration struct {
AppConfig ApplicationsConfig `yaml:"Application,omitempty"`
ThemeConfig ThemeConfig `yaml:"Theme,omitempty"`
SettingsConfig SettingsConfig `yaml:"Settings"`
AppConfig ApplicationsConfig `yaml:"Application,omitempty"`
ThemeConfig ThemeConfig `yaml:"Theme,omitempty"`
}

type SettingsConfig struct {
HideHelpOnStartup bool `yaml:"HideHelpOnStartup"`
}

type ThemeConfig struct {
Expand Down Expand Up @@ -50,16 +55,18 @@ type Config struct {
}

func Init() Config {
cfg := Config{}

cfg.file = *flag.String("config", "~/.config/nachrichten/config.yaml", "Path to configuration file")
configFile := flag.String("config", "~/.config/nachrichten/config.yaml", "Path to configuration file")

flag.Parse()
cfg := Config{
file: *configFile,
}
return cfg
}

func (c Config) Load() Configuration {
var config Configuration
config := defaultConfiguration()

data, err := os.ReadFile(c.file)
if err != nil {
Expand All @@ -69,3 +76,11 @@ func (c Config) Load() Configuration {
_ = yaml.Unmarshal(data, &config)
return config
}

func defaultConfiguration() Configuration {
return Configuration{
SettingsConfig: SettingsConfig{
HideHelpOnStartup: false,
},
}
}
33 changes: 17 additions & 16 deletions pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ func InitialModel(c config.Configuration) Model {
style = config.NewsStyle(config.DefaultThemeConfiguration())
}

helpMode := 1
if c.SettingsConfig.HideHelpOnStartup {
helpMode = 0
}

m := Model{
configuration: c,
keymap: GetKeyMap(),
style: style,
ready: false,
help: NewHelper(style),
helpMode: 1,
helpMode: helpMode,
reader: viewport.New(0, 0),
spinner: NewDotSpinner(),
focus: 0,
Expand Down Expand Up @@ -112,11 +117,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tagesschau.News:
m.news = tagesschau.News(msg)
m.InitLists([][]tagesschau.NewsEntry{m.news.NationalNews, m.news.RegionalNews})
width, _ := m.listSelectorDims()
for i := range m.lists {
m.lists[i].Title = lipgloss.PlaceHorizontal(width, lipgloss.Center, headerText)
m.lists[i].Styles.Title = m.style.TitleActiveStyle
}
m.resizeLists()
m.ready = true
case tea.KeyMsg:
switch {
Expand Down Expand Up @@ -189,33 +190,33 @@ func (m *Model) updateSizes(width, height int) {

m.reader.YPosition = m.readerHeaderHeight()

m.resizeLists()

m.reader.Width, m.reader.Height = m.readerDims()
m.help.Width = m.width
}

func (m *Model) resizeLists() {
w, _ := m.listSelectorDims()
for i := range m.lists {
m.lists[i].SetSize(m.listOuterDims())
w, _ := m.listInnerDims()
m.lists[i].Title = lipgloss.PlaceHorizontal(w, lipgloss.Center, headerText)
m.lists[i].Styles.Title = m.style.TitleActiveStyle
}

m.reader.Width, m.reader.Height = m.readerDims()
m.help.Width = m.width
}

func (m Model) listOuterDims() (int, int) {
return m.width / 3, m.height - m.helperHeight() - 5
}

func (m Model) listInnerDims() (int, int) {
w, h := m.listOuterDims()
return w - 6, h
}

func (m Model) listSelectorDims() (int, int) {
w, h := m.listOuterDims()
return w - 4, h
}

func (m Model) readerDims() (int, int) {
lw, _ := m.listOuterDims()
return m.width - lw - 7, m.height - m.readerHeaderHeight() - m.readerFooterHeight() - m.helperHeight()
return m.width - lw - 6, m.height - m.readerHeaderHeight() - m.readerFooterHeight() - m.helperHeight()
}

func (m Model) readerHeaderHeight() int {
Expand Down

0 comments on commit 75d878c

Please sign in to comment.