From 125ef84fe64502d247b522aa6e37b4aa80cb4f10 Mon Sep 17 00:00:00 2001 From: Robert Cheramy Date: Tue, 10 Dec 2024 07:36:36 +0100 Subject: [PATCH] cumulus: remove all ANSI ESC, not only in prompt - now the output looks better - added an entry in CHANGELOG.md --- CHANGELOG.md | 1 + .../yaml/cumulus_MSN2010_5.9.2_nvue.yaml | 2 +- lib/oxidized/model/cumulus.rb | 9 +++++++-- spec/model/cumulus_spec.rb | 7 ++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fed31736..17f801530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/examples/device-simulation/yaml/cumulus_MSN2010_5.9.2_nvue.yaml b/examples/device-simulation/yaml/cumulus_MSN2010_5.9.2_nvue.yaml index 633f271cc..d4b63dbe8 100644 --- a/examples/device-simulation/yaml/cumulus_MSN2010_5.9.2_nvue.yaml +++ b/examples/device-simulation/yaml/cumulus_MSN2010_5.9.2_nvue.yaml @@ -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 diff --git a/lib/oxidized/model/cumulus.rb b/lib/oxidized/model/cumulus.rb index 47c67c9ba..deb80b5d9 100644 --- a/lib/oxidized/model/cumulus.rb +++ b/lib/oxidized/model/cumulus.rb @@ -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# - prompt /^(\e\[\?\d+h)?[\w.-]+@.+:.*# $/ + prompt /^[\w.-]+@.+:.*# $/ comment '# ' # add a comment in the final conf diff --git a/spec/model/cumulus_spec.rb b/spec/model/cumulus_spec.rb index 0db41b409..4895bbf7c 100644 --- a/spec/model/cumulus_spec.rb +++ b/spec/model/cumulus_spec.rb @@ -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