Skip to content

Commit

Permalink
cumulus: remove all ANSI ESC, not only in prompt
Browse files Browse the repository at this point in the history
- now the output looks better
- added an entry in CHANGELOG.md
  • Loading branch information
robertcheramy committed Dec 10, 2024
1 parent 6d28f00 commit 125ef84
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Added

### Changed
- cumulus: remove ANSI Escape codes (@alchemyx, @robertcheramy)

### Fixed
- tplink: send 'enable' before the enable password. Fixes #3271 (@robertcheramy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ commands:
exit: |-
exit
oxidized_output: |
\e[?2004l\r- header:
- header:
model: MSN2010
nvue-api-version: nvue_v1
rev-id: 1.0
Expand Down
9 changes: 7 additions & 2 deletions lib/oxidized/model/cumulus.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
class Cumulus < Oxidized::Model
using Refinements

# (\e\[\?\d+h)? - optional ANSI escape code
# Remove ANSI escape codes
expect /\e\[[0-?]*[ -\/]*[@-~]\r?/ do |data, re|
data.gsub re, ''
end

# The prompt has ANSI ESC codes, the are removed from the code above
# [\w.-]+@ - user@
# .+:.*# $ - host:path# <end of line>
prompt /^(\e\[\?\d+h)?[\w.-]+@.+:.*# $/
prompt /^[\w.-]+@.+:.*# $/
comment '# '

# add a comment in the final conf
Expand Down
7 changes: 6 additions & 1 deletion spec/model/cumulus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

it 'matches different prompts' do
_('root@spine1-nyc2:~# ').must_match Cumulus.prompt
_("\e[?2004hroot@spine1-nyc2:~#\x20").must_match Cumulus.prompt

# Prompt with ESC Codes
prompt = "\e[?2004hroot@spine1-nyc2:~#\x20"
# Remove the ESC Codes
prompt = @node.model.expects prompt
_(prompt).must_match Cumulus.prompt
end

it 'runs on MSN2010 with Cumulus Linux 5.9.2 (nvue mode)' do
Expand Down

0 comments on commit 125ef84

Please sign in to comment.