Skip to content

Commit

Permalink
Initialize to full screen (#16)
Browse files Browse the repository at this point in the history
* Highlight mentioned user with mixed case

* Initialize height to size of terminal

* Remove commented code

* Tidy go.mod
  • Loading branch information
atye authored Jul 16, 2021
1 parent 6bb4e6c commit efee034
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ require (
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2
github.com/spf13/cobra v1.2.1
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/atye/ttchat v0.0.0-20210713012411-a1146ad9a397 h1:uJejCV1Mg7NDyVPfUDTKUo/RmHgj3PONxA5zo9Zh3Vc=
github.com/atye/ttchat v0.0.0-20210713012411-a1146ad9a397/go.mod h1:venTexKBMRBkwk+Sw8iIXkk1qDKd8xOJUV6P0CIa0bU=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -154,7 +152,6 @@ github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
Expand Down Expand Up @@ -439,11 +436,13 @@ golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71 h1:X/2sJAybVknnUnV7AD2HdT6rm2p5BP6eH2j+igduWgk=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed h1:Ei4bQjjpYUsS4efOUz+5Nz++IVkHk87n2zBA0NxBWc0=
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
8 changes: 1 addition & 7 deletions internal/cmd/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ ttchat --channel ludwig --lines 5
errExit(ErrNoChannel)
}

lines, err := cmd.Flags().GetInt("lines")
if err != nil {
errExit(err)
}

token, err := cmd.Flags().GetString("token")
if err != nil {
errExit(err)
Expand Down Expand Up @@ -136,7 +131,7 @@ ttchat --channel ludwig --lines 5
// Create IRC client and start
ircClient := client.NewGempirClient(conf.Username, channel, accessToken)
c := irc.NewIRCService(displayName, channel, ircClient)
if tea.NewProgram(terminal.NewModel(lines, c), tea.WithAltScreen()).Start() != nil {
if tea.NewProgram(terminal.NewModel(c), tea.WithAltScreen()).Start() != nil {
errExit(err)
}
},
Expand All @@ -149,7 +144,6 @@ ttchat --channel ludwig --lines 5
}

rootCmd.Flags().StringP("token", "t", "", `oauth token of the from "oauth:token" or "token"`)
rootCmd.Flags().IntP("lines", "l", 20, "number of lines for viewing chat, increase to see more messages")
return rootCmd
}

Expand Down
2 changes: 1 addition & 1 deletion internal/irc/irc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c IRCService) Publish(msg string) {
func highlightUserMentions(text string, displayName string) string {
texts := strings.Split(text, " ")
for i, w := range texts {
if strings.Contains(w, fmt.Sprintf("@%s", displayName)) {
if strings.Contains(strings.ToLower(w), fmt.Sprintf("@%s", strings.ToLower(displayName))) {
texts[i] = UserHighLightStyle.Render(w)
}
}
Expand Down
10 changes: 10 additions & 0 deletions internal/irc/irc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func TestGetMessageSource(t *testing.T) {
lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(DefaultNameColor)).Render("foo"),
fmt.Sprintf("hi %s", UserHighLightStyle.Render("@user")),
},
{
"incoming mention mix case",
"User",
types.PrivateMessage{
Name: "foo",
Text: "hi @user",
},
lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(DefaultNameColor)).Render("foo"),
fmt.Sprintf("hi %s", UserHighLightStyle.Render("@user")),
},
{
"incoming is you",
"user",
Expand Down
34 changes: 23 additions & 11 deletions internal/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ type Model struct {
messages []types.Message
ti textinput.Model
t Twitch
mode mode
}

type mode int

const (
Initialize mode = iota
Run
)

type noOpMessage struct{}

func (m noOpMessage) GetName() string {
Expand All @@ -53,21 +61,16 @@ func (m noOpMessage) FromMyself() bool {
return false
}

func NewModel(height int, t Twitch) Model {
func NewModel(t Twitch) Model {
ti := textinput.NewModel()
ti.Placeholder = "Send a message"
ti.Focus()

var m []types.Message
for i := 0; i < height; i++ {
m = append(m, types.Message(noOpMessage{}))
}

return Model{
in: t.GetMessageSource(),
messages: m,
ti: ti,
t: t,
in: t.GetMessageSource(),
mode: Initialize,
ti: ti,
t: t,
}
}

Expand Down Expand Up @@ -102,7 +105,16 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

case tea.WindowSizeMsg:
m.ti.Width = msg.Width
switch m.mode {
case Initialize:
msgs := make([]types.Message, msg.Height/2)
for i := 0; i < msg.Height/2; i++ {
msgs[i] = types.Message(noOpMessage{})
}
m.messages = msgs
m.mode = Run
default:
}
return m, listenForMessages(m.in)

case types.Message:
Expand Down

0 comments on commit efee034

Please sign in to comment.