diff options
| author | citrons <citrons@mondecitronne.com> | 2025-06-01 18:04:40 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-06-01 18:04:40 -0500 |
| commit | f50a839609847169702d76560dcdc7481099d7bc (patch) | |
| tree | 369ff2ca320b53a28e1d1dbea0effbf6f6388d9b /client | |
| parent | ccea376f5750629c2a82b1f24251e52756876f5d (diff) | |
user list
Diffstat (limited to 'client')
| -rw-r--r-- | client/channel_window.go | 63 | ||||
| -rw-r--r-- | client/command.go | 11 | ||||
| -rw-r--r-- | client/help.go | 1 |
3 files changed, 75 insertions, 0 deletions
diff --git a/client/channel_window.go b/client/channel_window.go index e5e7e84..43ce83f 100644 --- a/client/channel_window.go +++ b/client/channel_window.go @@ -107,6 +107,69 @@ func (cw *channelWindow) leaveChannel() { globalApp.windowCache.Evict(cw.location) } +type userListMsg struct { + index int + channelName string + names []string +} + +func (u userListMsg) Id() string { + return "user list." + strconv.Itoa(u.index) +} + +func (u userListMsg) Show(odd bool) { + tui.Push("", tui.Box { + Width: tui.Fill, Height: tui.Children, Dir: tui.Right, + Style: &tui.Style {Bg: colorCmd[odd], Fg: tui.White}, + }) + nameStyle := &tui.Style {Bg: colorCmd[odd], Fg: tui.White, Bold: true} + + tui.Push("", tui.Box {Width: tui.TextSize, Height: tui.TextSize}) + tui.Text("* ", nil) + tui.Pop() + + tui.Push("", tui.Box {Width: tui.Fill, Height: tui.Children}) + tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize}) + tui.Text(strconv.Itoa(len(u.names)), nil) + tui.Text(" users in ", nil) + tui.Text(u.channelName, nameStyle) + tui.Pop() + for _, name := range u.names { + tui.Push("", tui.Box { + Width: tui.Fill, Height: tui.Children, Dir: tui.Right, + }) + + tui.Push("", tui.Box {Width: tui.TextSize, Height: tui.TextSize}) + tui.Text(" * ", nil) + tui.Pop() + + tui.Push("", tui.Box {Width: tui.TextSize, Height: tui.TextSize}) + tui.Text(name, nameStyle) + tui.Pop() + + tui.Pop() + } + tui.Pop() + + tui.Pop() +} + +func (cw *channelWindow) userList(callback func(userListMsg)) { + ch := cw.getChannel() + cb := func(response proto.Command) { + if response.Kind != "list" { + return + } + var names []string + for _, u := range response.Args { + names = append(names, u.Fields[""]) + } + lastIndex++ + callback(userListMsg {lastIndex, ch.Fields[""], names}) + } + globalApp.Request(proto.NewCmd("list", cw.location.id), cb) +} + func (cw *channelWindow) ShowStatusLine() { ch := cw.getChannel() if ch == nil { diff --git a/client/command.go b/client/command.go index 4d0d5c1..101a5aa 100644 --- a/client/command.go +++ b/client/command.go @@ -79,6 +79,17 @@ func (a *application) doCommand(command string, args []string, text string) { win.(*channelWindow).leaveChannel() } a.currentWindow = cmdWindowLocation {} + case "list": + if !argN(0) { + break + } + win := a.windowCache.Get(a.currentWindow) + switch win.(type) { + case *channelWindow: + win.(*channelWindow).userList(func(msg userListMsg) { + a.cmdWindow.buf.Add(msg) + }) + } case "create": if !argN(1) { break diff --git a/client/help.go b/client/help.go index 55509b4..a6f1797 100644 --- a/client/help.go +++ b/client/help.go @@ -14,6 +14,7 @@ var helpTexts = []helpText { helpText {"help", "[command]", "view/list command descriptions"}, helpText {"nick", "<name>", "change your username"}, helpText {"join", "<name>", "join the channel with this name"}, + helpText {"list", "", "list users in the currently shown channel"}, helpText {"leave", "", "leave the currently shown channel"}, helpText {"create", "<name>", "create a channel with this name"}, helpText {"quit", "", "exit the application"}, |
