Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: application skeleton #100

Merged
merged 14 commits into from
Jan 15, 2020
Merged

client: application skeleton #100

merged 14 commits into from
Jan 15, 2020

Conversation

buck54321
Copy link
Member

This is a basic skeleton for a client app. It enables running an HTTP server or an RPC server. They both use the same client core, from the new core module. The default behavior is to run the servers from a simple but expandable TUI, but they can also be run without the TUI via command-line arguments or configuration file. Placeholder packages for the actual servers are in place, but don't do anything yet. A basic TUI infrastructure is built on tview, with enough code to demonstrate its use, but ultimately no functionality yet.

I'm hoping this provides a good framework on which concurrent development can proceed. I plan on getting into the web server this week, and maybe @JoeGruffins could continue fiddling with the TUI, or get into the RPC server. Once the web server is up, there will be front-end work to do there too. @dnldd can import and make use of the the order book code in the client core, and then expand from there.

@JoeGruffins
Copy link
Member

Looks good to me!

@chappjc
Copy link
Member

chappjc commented Dec 11, 2019

Good foundation for the client.
Looks like you'll want to rm the binary client/cmd/dexclient/dexclient

@buck54321
Copy link
Member Author

The dexclient binary actually snuck into master with some earlier client stuff. This PR removes it.

@chappjc
Copy link
Member

chappjc commented Dec 11, 2019

Oh, whoops. I read the diff backwards.

@buck54321 buck54321 marked this pull request as ready for review December 30, 2019 12:53
Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. The left side for me, one character is cut off. I guess could use a way to resize... or the dots, like "Accounts & Wa..."

pic

dex

Also, building with the --race flag and going to either web or rpc server and pressing enter twice finds two data races.

pic

dexrace

And, the white text on a grey background is difficult for me to see everywhere...

client/cmd/dexc/main.go Outdated Show resolved Hide resolved
client/cmd/dexc/main.go Outdated Show resolved Hide resolved
client/cmd/dexc/main.go Outdated Show resolved Hide resolved
client/cmd/dexc/ui/accountsview.go Outdated Show resolved Hide resolved
Comment on lines +102 to +117
if _, ok := err.(*os.PathError); !ok {
fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr)
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use go's new error unwrapping here.
https://golang.org/pkg/errors/

if errors.Is(err, os.PathError) {
        fmt.Fprintln(os.Stderr, err)
        parser.WriteHelp(os.Stderr)
	return nil, err
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.PathError is a type, not a sentinel, so I think you would need to use errors.As here, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dajohi does this work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would be As, but I'm comfortable with it the old way too.

client/cmd/dexc/ui/log.go Outdated Show resolved Hide resolved
client/cmd/dexc/ui/marketview.go Outdated Show resolved Hide resolved
client/cmd/dexc/ui/marketview.go Outdated Show resolved Hide resolved
client/cmd/dexc/ui/serverview.go Outdated Show resolved Hide resolved
Comment on lines +88 to +98
var welcomeMessage = "Welcome to Decred DEX. Use [#838ac7]Up[white] and " +
"[#838ac7]Down[white] arrows and then press [#838ac7]Enter[white] to select" +
" a new view. The [#838ac7]Escape[white] key will usually toggle the focus" +
" between the menu and the currently selected view. When the selected view" +
" is focused, most navigation can be done with your the [#838ac7]Left" +
"[white] and [#838ac7]Right[white] arrows, or alternatively [#838ac7]Tab" +
"[white] and [#838ac7]Shift+Tab[white]. Use [#838ac7]Escape[white] to remove" +
" focus from a form element."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The white on grey is hard for me to see...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

White on grey? Do you mean the purple parts? The white text with default background is default console coloring, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the first pic I uploaded you can see what I see by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh weird. I'll look into it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tview.Styles.PrimitiveBackgroundColor = backgroundColor

See if that works for you when you get a chance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! so, running like so xterm ./dexc and I get a nice picture. Creating a new xterm window for the app has fixed the colors for me.

pic

colors

Copy link
Member Author

@buck54321 buck54321 Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What interesting is that the inline-colored (1) next to Notifications is colored yellow instead of orange, and the inline key specifier text in the application log text is not purple. So it looks like some color incompatibility problems in general. Maybe you could peek around once this is merged and see if you can find better color values.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the purple isn't showing through at all for me. Are you using xterm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I didn't realize it was purple, that's another constant you could make...

Copy link
Member Author

@buck54321 buck54321 Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The color incompatibility is especially odd consider tview is based on tcell, whose readme opens with

Tcell is a Go package that provides a cell based view for text terminals, like xterm.

Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm?

Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review

client/cmd/dexc/main.go Outdated Show resolved Hide resolved
Comment on lines +34 to +38
// DRAFT NOTE: It's a little odd that the Configure function is from the ui
// package. The ui.Config struct is used both here and in ui. Could create a
// types package used by both, but doing it this way works for now.
Copy link
Member

@chappjc chappjc Jan 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only see createApp() in cmd/dexc/ui/widgets.go accessing the package-level cfg variable. All of config.go could be moved up to cmd/dexc if we make a separate ui.Config struct that has only what ui.createApp needs. This would be nice anyway since the Config struct used by go-flags has fields (and all struct field tags) that are only relevant to package main. But you're right, this does work for now.

client/cmd/dexc/ui/config_test.go Outdated Show resolved Hide resolved
client/cmd/dexc/ui/journal_test.go Show resolved Hide resolved
client/cmd/dexc/ui/depthchart.go Outdated Show resolved Hide resolved
client/cmd/dexc/ui/depthchart.go Outdated Show resolved Hide resolved
@buck54321
Copy link
Member Author

I must've botched a rebase somewhere. I think I've got it back now, but my history might be a little funky.

Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really slick looking and it all seems to work right in my testing. It takes a little getting used to tabs to go between test boxes and buttons when arrows are intuitive though.

client/cmd/dexc/ui/accountsview.go Show resolved Hide resolved
Comment on lines +102 to +117
if _, ok := err.(*os.PathError); !ok {
fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr)
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would be As, but I'm comfortable with it the old way too.

client/cmd/dexc/ui/depthchart.go Outdated Show resolved Hide resolved
client/cmd/dexc/ui/depthchart.go Outdated Show resolved Hide resolved
client/cmd/dexc/ui/depthchart.go Show resolved Hide resolved
Comment on lines +101 to +103
app.QueueUpdate(func() {
log.Errorf("interpolate error: %v", err)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, not too bad after all. 🤦‍♂️ I missed that app.QueueUpdate was available here.

This is a basic skeleton for a client app. It enables running an HTTP
server or an RPC server. They both use the same client core, from the
new core module. The default behavior is to run the servers from a
simple but expandable TUI, but they can also be run without the TUI via
command-line arguments or configuration file. Placeholder packages for the
actual servers are in place, but don't do anything yet. A basic TUI
infrastructure is built on tview, with enough code to demonstrate its use,
but ultimately no functionality yet. I'm hoping this provides a good
framework on which concurrent development can proceed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants