Skip to content

Commit

Permalink
Fix cb psql line wrapping issue.
Browse files Browse the repository at this point in the history
It was reported in #158 that `cb psql` was having an issue with line
wrapping when text was entered beyond the bounds of the terminal window.
It turns out that this issue was related to characters in the prompt
being `Colorized`. And it was these bytes of the resulting string that
were causing the issue. So, we've simply removed the `Colorize` step
associated with this particular output. This does not impact the
coloring of the text in the prompt as that's part of the configured
`PROMPT1` in the resulting `.psqlrc`.

We've also take the opportunity here to update the uri fetching for the
`user` role which was missed as part of #162.
  • Loading branch information
abrightwell committed May 9, 2024
1 parent 704e6b2 commit bc166ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- `cb config-param set` issue truncating values with multiple `=` characters.
- `cb psql` prompt line wrapping issue.
- `cb uri` retrieving correct `user` role credentials for a replica.

## [3.5.0] - 2024-01-31
Expand Down
1 change: 1 addition & 0 deletions spec/cb/psql_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Spectator.describe CB::Psql do

expect(client).to receive(:get_cluster).and_return(cluster)
expect(client).to receive(:create_role).and_return(role)
expect(client).to receive(:get_role).and_return(role)
expect(client).to receive(:get_team).and_return(team)

action.call
Expand Down
20 changes: 9 additions & 11 deletions src/cb/psql.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@ module CB
validate

c = client.get_cluster cluster_id[:cluster]
team = client.get_team c.team_id

uri = if @role == "user"
client.create_role(cluster_id[:cluster]).uri
else
client.get_role(cluster_id[:cluster], @role.to_s).uri
end

raise Error.new "null uri" if uri.nil?
client.create_role(cluster_id[:cluster]) if @role == "user"
uri = client.get_role(cluster_id[:cluster], @role.to_s).uri
raise Error.new "unable to obtain uri for cluster" if uri.nil?

database.tap { |db| uri.path = db if db }

output << "connecting to "
team_name = print_team_slash_cluster c
output << team.name.colorize.t_alt << "/" if team.name
output << c.name.colorize.t_name << "\n"

cert_path = ensure_cert c.team_id
psqlrc_path = build_psqlrc c, team_name
psqlrc_path = build_psqlrc c, team.name

args = ARGV.skip 1

Expand Down Expand Up @@ -90,9 +88,9 @@ module CB
end
end

private def build_psqlrc(c, team_name) : String
private def build_psqlrc(c : Model::Cluster, team_name : String) : String
psqlpromptname = String.build do |s|
s << "%[%033[32m%]#{escape(team_name.to_s)}%[%033m%]" << "/" if team_name
s << "%[%033[32m%]#{escape(team_name)}%[%033m%]" << "/" if team_name
s << "%[%033[36m%]#{c.name}%[%033m%]"
end

Expand Down

0 comments on commit bc166ca

Please sign in to comment.