This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added printing div elements according to terminal width * added test class and UI differences * added menu printing
- Loading branch information
Showing
11 changed files
with
121 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(main) | ||
add_subdirectory(ui) | ||
add_subdirectory(boatTest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(common) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_library(boatTest_Common boatTest_common.cpp boatTest_common.h) | ||
target_include_directories(boatTest_Common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "boatTest_common.h" | ||
|
||
BoatTest::BoatTest() { name = "NONESPECIFIED"; } | ||
BoatTest::BoatTest(std::string id, std::vector<std::string> topics, std::vector<std::string> messages) | ||
{ | ||
name = id; | ||
ROS_topics = topics; | ||
ROS_messages = messages; | ||
} | ||
|
||
std::string BoatTest::getName() { return name; } | ||
std::vector<std::string> BoatTest::getROSTopics() { return ROS_topics; } | ||
std::vector<std::string> BoatTest::getROSMessages() { return ROS_messages; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef BOATTEST_COMMON_H_ | ||
#define BOATTEST_COMMON_H_ | ||
|
||
/* Include Files */ | ||
#include <string> | ||
#include <vector> | ||
|
||
/* Objects */ | ||
class BoatTest | ||
{ | ||
std::string name; | ||
std::vector<std::string> ROS_topics; | ||
std::vector<std::string> ROS_messages; | ||
|
||
public: | ||
BoatTest(); | ||
BoatTest(std::string name, std::vector<std::string> ROS_topics, std::vector<std::string> ROS_messages); | ||
std::string getName(); | ||
std::vector<std::string> getROSTopics(); | ||
std::vector<std::string> getROSMessages(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
add_executable(diagnostics diagnostics.cpp) | ||
|
||
target_link_libraries(diagnostics PRIVATE | ||
UI | ||
UI_Common | ||
) | ||
|
||
target_link_libraries(diagnostics PRIVATE boatTest_Common) | ||
target_include_directories(diagnostics PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
#include <iostream> | ||
|
||
#include "commonUI.h" | ||
#include "diagnostics.h" | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
CommonUI base_elements; | ||
|
||
std::cout << "Welcome to UBC Sailbot Diagnostics! The C++ version" << std::endl; | ||
base_elements.printDiv(); | ||
std::string title = "Welcome to UBC Sailbot Diagnostics!"; | ||
base_elements.printCenter(title); | ||
base_elements.printDiv(); | ||
|
||
CommonUI myObj; | ||
std::unordered_map<std::string, std::string> commands; | ||
commands["ab"] = "Test AB"; | ||
commands["cd"] = "Test CD"; | ||
base_elements.printMenu(commands); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef DIAGNOSTICS_H_ | ||
#define DIAGNOSTICS_H_ | ||
|
||
/* Include Files */ | ||
#include <iostream> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "boatTest_common.h" | ||
#include "commonUI.h" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
add_library(UI STATIC commonUI.cpp commonUI.h) | ||
target_include_directories(UI PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
add_library(UI_Common commonUI.cpp commonUI.h) | ||
target_include_directories(UI_Common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,46 @@ | ||
#include "commonUI.h" | ||
|
||
#include <sys/ioctl.h> | ||
#include <unistd.h> | ||
|
||
CommonUI::CommonUI() { terminal_width = getTerminalWidth(); } | ||
CommonUI::CommonUI(int user_set_width) { terminal_width = user_set_width; } | ||
|
||
int CommonUI::getTerminalWidth() | ||
{ | ||
int current_width; | ||
struct winsize size; | ||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); | ||
return size.ws_col; | ||
if (size.ws_col > TERMINAL_WIDTH_MIN) { | ||
current_width = static_cast<int>(size.ws_col * TERMINAL_WIDTH_SCALE); | ||
} else { | ||
current_width = size.ws_col; | ||
} | ||
return current_width; | ||
} | ||
|
||
void CommonUI::printDiv() const | ||
{ | ||
std::cout << std::endl; | ||
|
||
for (int i = 0; i < terminal_width; i++) { | ||
std::cout << '='; | ||
} | ||
|
||
std::cout << std::endl; | ||
} | ||
|
||
void CommonUI::printCenter(std::string contents) const | ||
{ | ||
int left_padding = (terminal_width / 2) - (contents.size() / 2); | ||
|
||
for (int pad = 0; pad < left_padding; pad++) { | ||
std::cout << ' '; | ||
} | ||
|
||
std::cout << contents << std::endl; | ||
} | ||
|
||
void CommonUI::printMenu(std::unordered_map<std::string, std::string> commands) | ||
{ | ||
for (const auto & command : commands) { | ||
std::cout << '[' << command.first << "]" << command.second << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters