Skip to content

Commit 4406d92

Browse files
authored
Avoid storing characters before finishing execution of echo command (#118)
* Avoid storing characters before finishing execution of echo command Signed-off-by: Denisa <[email protected]> * Enable ANS characters in windows Signed-off-by: Denisa <[email protected]> * Fix printing bug Signed-off-by: Denisa <[email protected]> * Change sleep duration in print_command Signed-off-by: Denisa <[email protected]> * fix tests Signed-off-by: Denisa <[email protected]> * Fix python linter Signed-off-by: Denisa <[email protected]> * Fix linter 2 Signed-off-by: Denisa <[email protected]> * fix linter 3 Signed-off-by: Denisa <[email protected]> --------- Signed-off-by: Denisa <[email protected]>
1 parent 9a794c0 commit 4406d92

26 files changed

+172
-95
lines changed

fastddsspy_tool/src/cpp/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ int main(
5151
int argc,
5252
char** argv)
5353
{
54+
// Enable ANSI colors fow windows
55+
eprosima::utils::enable_ansi_colors();
5456
// Initialize CommandlineArgs
5557
eprosima::spy::yaml::CommandlineArgsSpy commandline_args;
5658

fastddsspy_tool/src/cpp/tool/Controller.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,13 @@ void Controller::print_command_(
492492
}
493493

494494
// Wait for other command to stop printing topics
495+
input_.stdin_handler().set_ignore_input(true);
495496
input_.wait_something();
497+
input_.stdin_handler().set_ignore_input(false);
496498
model_->deactivate();
499+
500+
// Small delay to allow stdout to flush and avoid prompt overlap
501+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
497502
}
498503

499504
void Controller::version_command_(

fastddsspy_tool/src/cpp/tool/Input.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ class Input
3737
protected:
3838

3939
utils::CommandReader<CommandValue> reader_;
40+
41+
public:
42+
43+
/**
44+
* @brief Access the underlying stdin event handler to control input behavior.
45+
* Used for temporarily disabling history input (e.g., during interactive commands).
46+
*/
47+
eprosima::utils::event::StdinEventHandler& stdin_handler() noexcept
48+
{
49+
return reader_.stdin_handler();
50+
}
51+
4052
};
4153

4254
} /* namespace spy */

fastddsspy_tool/test/application/test_cases/one_shot_datareader_guid_dds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def __init__(self):
4141
arguments_spy=['--config-path', 'configuration', 'datareader',
4242
'01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3'],
4343
commands_spy=[],
44-
output="""\x1b[1;31m01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3 \
45-
does not match with any known reader.\x1b[0m\n"""
44+
output="""01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3 \
45+
does not match with any known reader.\n"""
4646
)

fastddsspy_tool/test/application/test_cases/one_shot_datawriter_guid_dds_fail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def __init__(self):
4141
arguments_spy=['--config-path', 'configuration', 'datawriter',
4242
'01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3'],
4343
commands_spy=[],
44-
output="""\x1b[1;31m01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3 \
45-
does not match with any known writer.\x1b[0m\n"""
44+
output="""01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3 \
45+
does not match with any known writer.\n"""
4646
)

fastddsspy_tool/test/application/test_cases/one_shot_null.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ def __init__(self):
3636
arguments_dds=[],
3737
arguments_spy=['nullarg'],
3838
commands_spy=[],
39-
output="""\x1b[1;31m<nullarg> is not a known command. \
40-
Use <help> command to see valid commands and arguments.\x1b[0m\n"""
39+
output="""<nullarg> is not a known command. \
40+
Use <help> command to see valid commands and arguments.\n"""
4141
)

fastddsspy_tool/test/application/test_cases/one_shot_participants_guid_dds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def __init__(self):
4141
arguments_spy=['--config-path', 'configuration', 'participant',
4242
'01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3'],
4343
commands_spy=[],
44-
output="""\x1b[1;31m01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3 \
45-
does not match with any known participant.\x1b[0m\n"""
44+
output="""01.0f.d8.74.d5.a0.cf.f4.00.00.00.00|0.0.1.3 \
45+
does not match with any known participant.\n"""
4646
)

fastddsspy_tool/test/application/test_cases/one_shot_show_fail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ def __init__(self):
3636
arguments_dds=[],
3737
arguments_spy=['show'],
3838
commands_spy=[],
39-
output="""\x1b[1;31mCommand <show> requires at least \
40-
one argument.\x1b[0m\n"""
39+
output="""Command <show> requires at least \
40+
one argument.\n"""
4141
)

fastddsspy_tool/test/application/test_cases/one_shot_show_topic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ def __init__(self):
3636
arguments_dds=[],
3737
arguments_spy=['show', 'hello'],
3838
commands_spy=[],
39-
output="""\x1b[1;31m<hello> does not match any topic discovered.\x1b[0m\n"""
39+
output="""<hello> does not match any topic discovered.\n"""
4040
)

fastddsspy_tool/test/application/test_cases/one_shot_show_topic_verbose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ def __init__(self):
3636
arguments_dds=[],
3737
arguments_spy=['show', 'hello', 'verbose'],
3838
commands_spy=[],
39-
output="""\x1b[1;31m<hello> does not match any topic discovered.\x1b[0m\n"""
39+
output="""<hello> does not match any topic discovered.\n"""
4040
)

fastddsspy_tool/test/application/test_cases/one_shot_topics_name.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ def __init__(self):
3636
arguments_dds=[],
3737
arguments_spy=['topics', 'hello'],
3838
commands_spy=[],
39-
output="""\x1b[1;31m<hello> does not match any topic \
40-
in the DDS network.\x1b[0m\n"""
39+
output="""<hello> does not match any topic \
40+
in the DDS network.\n"""
4141
)

fastddsspy_tool/test/application/test_cases/tool_datareader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def __init__(self):
3737
arguments_dds=[],
3838
arguments_spy=[],
3939
commands_spy=['datareader'],
40-
output=""">> \x1b[0m\n\n\n\n"""
40+
output="""\n"""
4141
)

fastddsspy_tool/test/application/test_cases/tool_datareader_dds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def __init__(self):
4040
arguments_dds=[],
4141
arguments_spy=['--config-path', 'configuration'],
4242
commands_spy=['datareader'],
43-
output=""">> \x1b[0m\n\n\n\n"""
43+
output="""\n"""
4444
)

fastddsspy_tool/test/application/test_cases/tool_datawriter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def __init__(self):
3737
arguments_dds=[],
3838
arguments_spy=[],
3939
commands_spy=['datawriter'],
40-
output=""">> \x1b[0m\n\n\n\n"""
40+
output="""\n"""
4141
)

fastddsspy_tool/test/application/test_cases/tool_datawriter_dds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self):
4040
arguments_dds=[],
4141
arguments_spy=['--config-path', 'configuration'],
4242
commands_spy=['datawriter'],
43-
output=""">> \x1b[0m- guid: %%guid%%\n\
43+
output="""- guid: %%guid%%\n\
4444
\n\
4545
participant: Participant_pub\n\
4646
\n\

fastddsspy_tool/test/application/test_cases/tool_help.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,54 @@ def __init__(self):
3737
arguments_dds=[],
3838
arguments_spy=[],
3939
commands_spy=['help'],
40-
output=""">> \x1b[0mFast DDS Spy is an interactive CLI that allow to instrospect DDS networks.\n\n\
41-
Each command shows data related with the network in Yaml format.\n\n\
42-
Commands available and the information they show:\n\n\
43-
\thelp : this help.\n\n\
44-
\tversion : tool version.\n\n\
45-
\tquit : exit interactive CLI and close program.\n\n\
46-
\tparticipants : DomainParticipants discovered in the network.\n\n\
47-
\tparticipants verbose : verbose information about DomainParticipants discovered in the network.\n\n\
48-
\tparticipants <Guid> : verbose information related with a specific DomainParticipant.\n\n\
49-
\twriters : DataWriters discovered in the network.\n\n\
50-
\twriters verbose : verbose information about DataWriters discovered in the network.\n\n\
51-
\twriters <Guid> : verbose information related with a specific DataWriter.\n\n\
52-
\treader : DataReaders discovered in the network.\n\n\
53-
\treader verbose : verbose information about DataReaders discovered in the network.\n\n\
54-
\treader <Guid> : verbose information related with a specific DataReader.\n\n\
55-
\ttopics : Topics discovered in the network in compact format.\n\n\
56-
\ttopics v : Topics discovered in the network.\n\n\
57-
\ttopics vv : verbose information about Topics discovered in the network.\n\n\
58-
\ttopics <name> : Topics discovered in the network filtered by name (wildcard allowed (*)).\n\n\
59-
\techo <name> : data of a specific Topic (Data Type must be discovered).\n\n\
60-
\techo <wildcard_name> : data of Topics matching the wildcard name (and whose Data Type is discovered).\n\n\
61-
\techo <name> verbose : data with additional source info of a specific Topic.\n\n\
62-
\techo <wildcard_name> verbose : data with additional source info of Topics matching the topic name (wildcard allowed (*)).\n\n\
63-
\techo all : verbose data of all topics (only those whose Data Type is discovered).\n\n\
64-
\n\n\
65-
Notes and comments:\n\n\
66-
\tTo exit from data printing, press enter.\n\n\
67-
\tEach command is accessible by using its first letter (h/v/q/p/w/r/t/s).\n\n\
68-
\n\n\
69-
For more information about these commands and formats, please refer to the documentation:\n\n\
70-
https://fast-dds-spy.readthedocs.io/en/latest/\n\n
71-
"""
40+
output=(
41+
'Fast DDS Spy is an interactive CLI that allow to instrospect DDS networks.\n\n'
42+
'Each command shows data related with the network in Yaml format.\n\n'
43+
'Commands available and the information they show:\n\n'
44+
'\thelp : this help.\n\n'
45+
'\tversion : tool version.\n\n'
46+
'\tquit : exit interactive CLI and close program.\n\n'
47+
'\tparticipants : DomainParticipants discovered in the '
48+
'network.\n\n'
49+
'\tparticipants verbose : verbose information about DomainParticipants '
50+
'discovered in the network.\n\n'
51+
'\tparticipants <Guid> : verbose information related with a specific '
52+
'DomainParticipant.\n\n'
53+
'\twriters : DataWriters discovered in the network.\n\n'
54+
'\twriters verbose : verbose information about DataWriters '
55+
'discovered in the network.\n\n'
56+
'\twriters <Guid> : verbose information related with a specific '
57+
'DataWriter.\n\n'
58+
'\treader : DataReaders discovered in the network.\n\n'
59+
'\treader verbose : verbose information about DataReaders '
60+
'discovered in the network.\n\n'
61+
'\treader <Guid> : verbose information related with a specific '
62+
'DataReader.\n\n'
63+
'\ttopics : Topics discovered in the network '
64+
'in compact format.\n\n'
65+
'\ttopics v : Topics discovered in the network.\n\n'
66+
'\ttopics vv : verbose information about Topics discovered '
67+
'in the network.\n\n'
68+
'\ttopics <name> : Topics discovered in the network filtered by '
69+
'name (wildcard allowed (*)).\n\n'
70+
'\techo <name> : data of a specific Topic '
71+
'(Data Type must be discovered).\n\n'
72+
'\techo <wildcard_name> : data of Topics matching the wildcard name '
73+
'(and whose Data Type is discovered).\n\n'
74+
'\techo <name> verbose : data with additional source info '
75+
'of a specific Topic.\n\n'
76+
'\techo <wildcard_name> verbose : data with additional source info '
77+
'of Topics matching the '
78+
'topic name (wildcard allowed (*)).\n\n'
79+
'\techo all : verbose data of all topics (only those whose '
80+
'Data Type is discovered).\n\n'
81+
'\n\n'
82+
'Notes and comments:\n\n'
83+
'\tTo exit from data printing, press enter.\n\n'
84+
'\tEach command is accessible by using its first letter (h/v/q/p/w/r/t/s).\n\n'
85+
'\n\n'
86+
'For more information about these commands and formats, '
87+
'please refer to the documentation:\n\n'
88+
'https://fast-dds-spy.readthedocs.io/en/latest/\n'
89+
)
7290
)

fastddsspy_tool/test/application/test_cases/tool_help_dds.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,54 @@ def __init__(self):
4040
arguments_dds=[],
4141
arguments_spy=['--config-path', 'configuration'],
4242
commands_spy=['help'],
43-
output=""">> \x1b[0mFast DDS Spy is an interactive CLI that allow to instrospect DDS networks.\n\n\
44-
Each command shows data related with the network in Yaml format.\n\n\
45-
Commands available and the information they show:\n\n\
46-
\thelp : this help.\n\n\
47-
\tversion : tool version.\n\n\
48-
\tquit : exit interactive CLI and close program.\n\n\
49-
\tparticipants : DomainParticipants discovered in the network.\n\n\
50-
\tparticipants verbose : verbose information about DomainParticipants discovered in the network.\n\n\
51-
\tparticipants <Guid> : verbose information related with a specific DomainParticipant.\n\n\
52-
\twriters : DataWriters discovered in the network.\n\n\
53-
\twriters verbose : verbose information about DataWriters discovered in the network.\n\n\
54-
\twriters <Guid> : verbose information related with a specific DataWriter.\n\n\
55-
\treader : DataReaders discovered in the network.\n\n\
56-
\treader verbose : verbose information about DataReaders discovered in the network.\n\n\
57-
\treader <Guid> : verbose information related with a specific DataReader.\n\n\
58-
\ttopics : Topics discovered in the network in compact format.\n\n\
59-
\ttopics v : Topics discovered in the network.\n\n\
60-
\ttopics vv : verbose information about Topics discovered in the network.\n\n\
61-
\ttopics <name> : Topics discovered in the network filtered by name (wildcard allowed (*)).\n\n\
62-
\techo <name> : data of a specific Topic (Data Type must be discovered).\n\n\
63-
\techo <wildcard_name> : data of Topics matching the wildcard name (and whose Data Type is discovered).\n\n\
64-
\techo <name> verbose : data with additional source info of a specific Topic.\n\n\
65-
\techo <wildcard_name> verbose : data with additional source info of Topics matching the topic name (wildcard allowed (*)).\n\n\
66-
\techo all : verbose data of all topics (only those whose Data Type is discovered).\n\n\
67-
\n\n\
68-
Notes and comments:\n\n\
69-
\tTo exit from data printing, press enter.\n\n\
70-
\tEach command is accessible by using its first letter (h/v/q/p/w/r/t/s).\n\n\
71-
\n\n\
72-
For more information about these commands and formats, please refer to the documentation:\n\n\
73-
https://fast-dds-spy.readthedocs.io/en/latest/\n\n
74-
"""
43+
output=(
44+
'Fast DDS Spy is an interactive CLI that allow to instrospect DDS networks.\n\n'
45+
'Each command shows data related with the network in Yaml format.\n\n'
46+
'Commands available and the information they show:\n\n'
47+
'\thelp : this help.\n\n'
48+
'\tversion : tool version.\n\n'
49+
'\tquit : exit interactive CLI and close program.\n\n'
50+
'\tparticipants : DomainParticipants discovered in the '
51+
'network.\n\n'
52+
'\tparticipants verbose : verbose information about DomainParticipants '
53+
'discovered in the network.\n\n'
54+
'\tparticipants <Guid> : verbose information related with a specific '
55+
'DomainParticipant.\n\n'
56+
'\twriters : DataWriters discovered in the network.\n\n'
57+
'\twriters verbose : verbose information about DataWriters '
58+
'discovered in the network.\n\n'
59+
'\twriters <Guid> : verbose information related with a specific '
60+
'DataWriter.\n\n'
61+
'\treader : DataReaders discovered in the network.\n\n'
62+
'\treader verbose : verbose information about DataReaders '
63+
'discovered in the network.\n\n'
64+
'\treader <Guid> : verbose information related with a specific '
65+
'DataReader.\n\n'
66+
'\ttopics : Topics discovered in the network '
67+
'in compact format.\n\n'
68+
'\ttopics v : Topics discovered in the network.\n\n'
69+
'\ttopics vv : verbose information about Topics discovered '
70+
'in the network.\n\n'
71+
'\ttopics <name> : Topics discovered in the network filtered by '
72+
'name (wildcard allowed (*)).\n\n'
73+
'\techo <name> : data of a specific Topic '
74+
'(Data Type must be discovered).\n\n'
75+
'\techo <wildcard_name> : data of Topics matching the wildcard name '
76+
'(and whose Data Type is discovered).\n\n'
77+
'\techo <name> verbose : data with additional source info '
78+
'of a specific Topic.\n\n'
79+
'\techo <wildcard_name> verbose : data with additional source info '
80+
'of Topics matching the '
81+
'topic name (wildcard allowed (*)).\n\n'
82+
'\techo all : verbose data of all topics (only those whose '
83+
'Data Type is discovered).\n\n'
84+
'\n\n'
85+
'Notes and comments:\n\n'
86+
'\tTo exit from data printing, press enter.\n\n'
87+
'\tEach command is accessible by using its first letter (h/v/q/p/w/r/t/s).\n\n'
88+
'\n\n'
89+
'For more information about these commands and formats, '
90+
'please refer to the documentation:\n\n'
91+
'https://fast-dds-spy.readthedocs.io/en/latest/\n'
92+
)
7593
)

fastddsspy_tool/test/application/test_cases/tool_null.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ def __init__(self):
3737
arguments_dds=[],
3838
arguments_spy=[],
3939
commands_spy=['null'],
40-
output=""">> \x1b[0m\x1b[1;31m<null> is not a known command. \
41-
Use <help> command to see valid commands and arguments.\x1b[0m\n\n\n\n"""
40+
output="""<null> is not a known command. \
41+
Use <help> command to see valid commands and arguments.\n"""
4242
)

fastddsspy_tool/test/application/test_cases/tool_participants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def __init__(self):
3737
arguments_dds=[],
3838
arguments_spy=[],
3939
commands_spy=['participants'],
40-
output=""">> \x1b[0m\n\n\n\n"""
40+
output="""\n"""
4141
)

fastddsspy_tool/test/application/test_cases/tool_participants_dds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self):
4040
arguments_dds=[],
4141
arguments_spy=['--config-path', 'configuration'],
4242
commands_spy=['participants'],
43-
output=""">> \x1b[0m- name: Participant_pub\n\
43+
output="""- name: Participant_pub\n\
4444
\n\
4545
guid: %%guid%%\n"""
4646
)

fastddsspy_tool/test/application/test_cases/tool_show_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def __init__(self):
3737
arguments_dds=[],
3838
arguments_spy=[],
3939
commands_spy=['show all \n'],
40-
output=""">> \x1b[0m\n\n"""
40+
output="""\n"""
4141
)

fastddsspy_tool/test/application/test_cases/tool_show_topic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ def __init__(self):
3737
arguments_dds=[],
3838
arguments_spy=[],
3939
commands_spy=['show topic'],
40-
output=""">> \x1b[0m\x1b[1;31m<topic> \
41-
does not match any topic discovered.\x1b[0m\n\n\n\n"""
40+
output="""<topic> \
41+
does not match any topic discovered.\n"""
4242
)

fastddsspy_tool/test/application/test_cases/tool_topics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def __init__(self):
3737
arguments_dds=[],
3838
arguments_spy=[],
3939
commands_spy=['topics'],
40-
output=""">> \x1b[0m\n\n\n\n"""
40+
output="""\n"""
4141
)

fastddsspy_tool/test/application/test_cases/tool_topics_dds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def __init__(self):
4040
arguments_dds=[],
4141
arguments_spy=['--config-path', 'configuration'],
4242
commands_spy=['topics'],
43-
output=""">> \x1b[0m- topic: HelloWorldTopic (HelloWorld) (1|0) [%%rate%% Hz]\n"""
43+
output="""- topic: HelloWorldTopic (HelloWorld) (1|0) [%%rate%% Hz]\n"""
4444
)

fastddsspy_tool/test/application/test_cases/tool_topics_dds_no_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ def __init__(self):
3838
arguments_dds=[],
3939
arguments_spy=[],
4040
commands_spy=['topics'],
41-
output=""">> \x1b[0m- topic: HelloWorldTopic (HelloWorld) (1|0) [%%rate%% Hz]"""
41+
output="""- topic: HelloWorldTopic (HelloWorld) (1|0) [%%rate%% Hz]\n"""
4242
)

0 commit comments

Comments
 (0)