From 84f0a15bc3513351edcc50a943bba875f4187f5d Mon Sep 17 00:00:00 2001 From: LeadRDRK Date: Tue, 9 Feb 2021 10:24:40 +0700 Subject: [PATCH] Proper PDCurses/Windows support and some other stuff * Added PDCurses support. Consequently, Windows is properly supported now * Use map.find instead map.at when parsing command line options (because I was an idiot and forgot that try doesn't catch out of range exceptions) * Fixed the options parser for asciiplay * Updated README --- README.md | 15 ++++++++++++++- src/asciienc/options.cpp | 7 +++---- src/asciiplay/CMakeLists.txt | 2 +- src/asciiplay/options.cpp | 16 +++++++--------- src/asciiplay/player.cpp | 3 +++ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 38a0c5c..6feaa3f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,19 @@ make ``` ## Windows Using a Unix-like environment with MinGW-w64 is recommended. The procedure is -exactly the same as Linux as described above. +exactly the same as Linux as described above. As for the curses library, PDCurses +with wincon is recommended. +# Usage +Example: Encoding a video from *.png files with audio +``` +asciienc -i path/to/frames_folder --ifmt png -fps 30 -a audio.ogg output.asv +``` +Example: Play a video +``` +asciiplay video.asv +``` +More information can found by executing the programs with the --help option. + +Please note that the user interface for asciiplay is incomplete and buggy. It can be disabled using the -disableui option. # Demo As usual, here's the classic [Bad Apple!!](https://youtu.be/C_qwSUhRv8U) diff --git a/src/asciienc/options.cpp b/src/asciienc/options.cpp index 569e08f..3ee4803 100644 --- a/src/asciienc/options.cpp +++ b/src/asciienc/options.cpp @@ -57,14 +57,13 @@ Options::Options(int &argc, char** &argv) break; } - int optionType; - try { - optionType = optionsMap.at(option); - } catch (int e) { + auto it = optionsMap.find(option); + if (it == optionsMap.end()) { std::cout << "Error: Invalid option: " << option << "\n\n"; bad = true; break; } + int optionType = it->second; if (optionType >= INPUT && optionType <= OFMT) { // options within this range requires an argument diff --git a/src/asciiplay/CMakeLists.txt b/src/asciiplay/CMakeLists.txt index 46f4592..a90e36f 100644 --- a/src/asciiplay/CMakeLists.txt +++ b/src/asciiplay/CMakeLists.txt @@ -18,4 +18,4 @@ find_package(Curses REQUIRED) add_executable(asciiplay ${SOURCES} ${HEADERS}) set_property(TARGET asciiplay PROPERTY CXX_STANDARD 17) target_include_directories(asciiplay PRIVATE .. ${EXT_INCLUDE_DIRS} ${CURSES_INCLUDE_DIRS}) -target_link_libraries(asciiplay PRIVATE Threads::Threads ${CMAKE_DL_LIBS} ${CURSES_LIBRARIES}) \ No newline at end of file +target_link_libraries(asciiplay PRIVATE Threads::Threads ${CMAKE_DL_LIBS} ${CURSES_LIBRARIES}) diff --git a/src/asciiplay/options.cpp b/src/asciiplay/options.cpp index d89d464..24ee45b 100644 --- a/src/asciiplay/options.cpp +++ b/src/asciiplay/options.cpp @@ -30,19 +30,17 @@ Options::Options(int &argc, char** &argv) if (bad) break; std::string option(argv[i]); - if (i == argc - 1) { - input = option; - break; - } - - int optionType; - try { - optionType = optionsMap.at(option); - } catch (int e) { + auto it = optionsMap.find(option); + if (it == optionsMap.end()) { + if (i == argc - 1) { + input = option; + break; + } std::cout << "Error: Invalid option: " << option << "\n\n"; bad = true; break; } + int optionType = it->second; switch (optionType) { case HELP: diff --git a/src/asciiplay/player.cpp b/src/asciiplay/player.cpp index 16e69bb..d8a3105 100644 --- a/src/asciiplay/player.cpp +++ b/src/asciiplay/player.cpp @@ -33,6 +33,9 @@ static char LOGO[1473] = #include #include +#define PDC_WIDE +#define PDC_FORCE_UTF8 +#define PDC_NCMOUSE #include namespace chrono = std::chrono;