-
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.
- Loading branch information
1 parent
c8911ee
commit ebdec95
Showing
11 changed files
with
280 additions
and
53 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
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
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
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,40 @@ | ||
#pragma once | ||
|
||
#ifdef WIN32 | ||
|
||
// _kbhit() is originally from this library but it is windows only | ||
#include <conio.h> | ||
|
||
#else | ||
// taken from https://www.flipcode.com/archives/_kbhit_for_Linux.shtml | ||
// very slightly modified (#include <strops.h> to #include <sys/ioctl.h>) | ||
|
||
/** | ||
Linux (POSIX) implementation of _kbhit(). | ||
Morgan McGuire, [email protected] | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <sys/select.h> | ||
#include <termios.h> | ||
#include <sys/ioctl.h> | ||
|
||
int _kbhit() { | ||
static const int STDIN = 0; | ||
static bool initialized = false; | ||
|
||
if (! initialized) { | ||
// Use termios to turn off line buffering | ||
termios term; | ||
tcgetattr(STDIN, &term); | ||
term.c_lflag &= ~ICANON; | ||
tcsetattr(STDIN, TCSANOW, &term); | ||
setbuf(stdin, NULL); | ||
initialized = true; | ||
} | ||
|
||
int bytesWaiting; | ||
ioctl(STDIN, FIONREAD, &bytesWaiting); | ||
return bytesWaiting; | ||
} | ||
#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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "termutils.hpp" | ||
|
||
namespace vtt { | ||
|
||
TermUtils::TermUtils() | ||
{ | ||
hidden = false; | ||
} | ||
|
||
// taken from https://stackoverflow.com/a/23370070 | ||
#ifdef WIN32 | ||
|
||
std::array<int, 2> TermUtils::getTerminalDimensions() | ||
{ | ||
CONSOLE_SCREEN_BUFFER_INFO csbi; | ||
int columns, rows; | ||
|
||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); | ||
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1; | ||
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; | ||
|
||
std::array<int, 2> dimensions; | ||
dimensions[0] = columns; | ||
dimensions[1] rows; | ||
|
||
return dimensions; | ||
} | ||
|
||
void TermUtils::hideInput() | ||
{ | ||
if (!hidden) | ||
{ | ||
this->hStdin = GetStdHandle(STD_INPUT_HANDLE); | ||
this->mode = 0; | ||
GetConsoleMode(hStdin, &mode); | ||
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT)); | ||
hidden = true; | ||
} | ||
} | ||
|
||
void TermUtils::showInput() | ||
{ | ||
if (hidden) | ||
{ | ||
SetConsoleMode(hStdin, mode); | ||
hidden = false; | ||
} | ||
} | ||
#else | ||
|
||
std::array<int, 2> TermUtils::getTerminalDimensions() | ||
{ | ||
struct winsize w; | ||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); | ||
std::array<int, 2> dimensions; | ||
dimensions[0] = w.ws_col; | ||
dimensions[1] = w.ws_row; | ||
|
||
return dimensions; | ||
} | ||
|
||
void TermUtils::hideInput() | ||
{ | ||
if (!hidden) | ||
{ | ||
tcgetattr(STDIN_FILENO, &oldt); | ||
newt = oldt; | ||
newt.c_lflag &= ~ECHO; | ||
tcsetattr(STDIN_FILENO, TCSANOW, &newt); | ||
hidden = true; | ||
} | ||
} | ||
|
||
void TermUtils::showInput() | ||
{ | ||
if (hidden) | ||
{ | ||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); | ||
hidden = false; | ||
} | ||
} | ||
#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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#ifdef WIN32 | ||
#include <windows.h> | ||
#else | ||
#include <sys/ioctl.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <termios.h> | ||
#endif | ||
#include <array> | ||
|
||
namespace vtt { | ||
|
||
class TermUtils { | ||
private: | ||
bool hidden; | ||
#ifdef WIN32 | ||
HANDLE hStdin; | ||
DWORD mode; | ||
#else | ||
termios oldt; | ||
termios newt; | ||
#endif | ||
public: | ||
TermUtils(); | ||
static std::array<int, 2> getTerminalDimensions(); | ||
void hideInput(); | ||
void showInput(); | ||
}; | ||
|
||
} |
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
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
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,67 @@ | ||
#include <iostream> | ||
#include <termio.h> | ||
#include "../libs/variousutils.hpp" | ||
#include "../libs/termutils.hpp" | ||
#include "../libs/binaryutils.hpp" | ||
#include "../libs/_kbhit.h" | ||
|
||
using namespace std; | ||
using namespace vtt; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
filesystem::path path; | ||
if (argc > 1) | ||
{ | ||
path = filesystem::absolute(argv[1]); | ||
if (!filesystem::is_directory(path)) | ||
path = path.parent_path(); | ||
} | ||
else | ||
path = filesystem::current_path(); | ||
|
||
auto files = VariousUtils::getFilesInDir(path); | ||
|
||
TermUtils tu; | ||
int fileIndex = 0; | ||
cout << "Selected file: " << files[fileIndex].d_name << "\n"; | ||
unsigned char keyValue; | ||
cout << "waiting for a keypress...\npress ESC to close the program.\n" << flush; | ||
tu.hideInput(); | ||
while (true) | ||
{ | ||
if (_kbhit()) | ||
{ | ||
std::vector<char> vals; | ||
while (_kbhit()) | ||
{ | ||
cin >> keyValue; | ||
vals.push_back(keyValue); | ||
} | ||
int combinedKeyCode = BinaryUtils::byteArrayToUint((Byte*)vals.data(), vals.size()); | ||
|
||
// right arrow | ||
if (combinedKeyCode == 1792835) | ||
{ | ||
fileIndex = (fileIndex + 1) % files.size(); | ||
cout << "Selected file: " << files[fileIndex].d_name << "\n"; | ||
} | ||
|
||
// left arrow | ||
if (combinedKeyCode == 1792836) | ||
{ | ||
fileIndex--; | ||
if (fileIndex < 0) fileIndex += files.size(); | ||
cout << "Selected file: " << files[fileIndex].d_name << "\n"; | ||
} | ||
|
||
// ESC | ||
if (combinedKeyCode == 27) | ||
break; | ||
} | ||
} | ||
tu.showInput(); | ||
cout << "done\n"; | ||
|
||
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,22 @@ | ||
#pragma once | ||
|
||
#include "../transcoder/videotranscoder.hpp" | ||
#include "../decoder/vtdidecoder.hpp" | ||
#include "../img-viewer/imgviewer.hpp" | ||
|
||
namespace vtt { | ||
|
||
enum FileType { image, video }; | ||
|
||
struct File { | ||
std::string path; | ||
FileType type; | ||
bool readyToView; | ||
}; | ||
|
||
class MediaViewer { | ||
private: | ||
std::vector<File> files; | ||
}; | ||
|
||
} |
Oops, something went wrong.