Skip to content

Commit 15fcdca

Browse files
committed
Finalize the def encoding settings
Add my own cpp header only lin -> alib - Used alib to decorate some area
1 parent 2138176 commit 15fcdca

File tree

2 files changed

+207
-7
lines changed

2 files changed

+207
-7
lines changed

lib/alib.hpp

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
alib is a header only library which offers many usefull and frequently used C++
3+
functions which are not present in standard c++ library. The library is under
4+
GPL3 license and is open for others to contribute to this project. This library
5+
supports multi platform. It works on both windows and Linux operating system.
6+
7+
The project is inspired from the rang project.
8+
9+
The project is maintained by Mushfiqur Rahman Abir aka Abir-Tx.
10+
11+
12+
Current Version: v1.0
13+
Maintainer: Mushfiqur Rahman Abir
14+
Developer Profile https://www.github.com/Abir-Tx
15+
*/
16+
17+
#if !defined(ALIB_DOT_HPP)
18+
#define ALIB_DOT_HPP
19+
20+
// Defining the different platforms
21+
#if defined(__unix__) || defined(__unix) || defined(__linux__)
22+
#define LINUX
23+
#elif defined(WIN32) || defined(_WIN32) || defined(_WIN64)
24+
#define WINDOWS
25+
#elif defined(__APPLE__) || defined(__MACH__)
26+
#define MAC
27+
#else
28+
#error Unknown
29+
#endif
30+
31+
// Including platform specific files
32+
#if defined(LINUX) || defined(MAC)
33+
#include <sys/ioctl.h> /* For getting terminal height and width. See consoleWidth() & consoleHeight() */
34+
#include <unistd.h>
35+
#elif defined(WINDOWS)
36+
#include <windows.h>
37+
#endif
38+
39+
// Including platform independent files
40+
#include <iomanip>
41+
#include <iostream>
42+
#include <vector>
43+
44+
#include "rang.hpp" /* A third party library for console text styling and coloring */
45+
46+
// Functions
47+
namespace alib {
48+
// Function for dynamically decorating a text
49+
void decorateMe(std::string textToDecor) {
50+
using namespace rang;
51+
52+
int charSize = textToDecor.capacity();
53+
std::cout << std::endl;
54+
std::cout << fg::red;
55+
for (int i = 0; i < (charSize * 2); i++) { std::cout << "_"; }
56+
std::cout << fg::reset;
57+
std::cout << std::endl;
58+
59+
std::cout << fg::blue << style::bold << textToDecor << style::reset
60+
<< fg::reset;
61+
62+
std::cout << std::endl;
63+
std::cout << fg::red;
64+
for (int i = 0; i < (charSize * 2); i++) { std::cout << "_"; }
65+
std::cout << fg::reset;
66+
std::cout << std::endl;
67+
std::cout << std::endl;
68+
}
69+
70+
void decorateMe(std::string textToDecor, unsigned short int lineBreaksNumber) {
71+
using namespace rang;
72+
73+
int charSize = textToDecor.capacity();
74+
std::cout << std::endl;
75+
std::cout << fg::red;
76+
for (int i = 0; i < (charSize * 2); i++) { std::cout << "_"; }
77+
std::cout << fg::reset;
78+
for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; }
79+
std::cout << fg::blue << style::bold << textToDecor << style::reset
80+
<< fg::reset;
81+
82+
for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; }
83+
std::cout << fg::red;
84+
for (int i = 0; i < (charSize * 2); i++) { std::cout << "_"; }
85+
std::cout << fg::reset;
86+
std::cout << std::endl;
87+
std::cout << std::endl;
88+
}
89+
90+
void decorateMe(std::string textToDecor, unsigned short int lineBreaksNumber,
91+
std::string decorator) {
92+
using namespace rang;
93+
94+
int charSize = textToDecor.capacity();
95+
std::cout << std::endl;
96+
std::cout << fg::red;
97+
for (int i = 0; i < (charSize * 2); i++) { std::cout << decorator; }
98+
std::cout << fg::reset;
99+
for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; }
100+
std::cout << fg::blue << style::bold << textToDecor << style::reset
101+
<< fg::reset;
102+
103+
for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; }
104+
std::cout << fg::red;
105+
for (int i = 0; i < (charSize * 2); i++) { std::cout << decorator; }
106+
std::cout << fg::reset;
107+
std::cout << std::endl;
108+
std::cout << std::endl;
109+
}
110+
111+
/* Clears the screen depending on OS */
112+
void clrscr() {
113+
#if defined(LINUX) || defined(MAC)
114+
system("clear");
115+
#elif defined(WINDOWS)
116+
system("cls");
117+
#endif
118+
}
119+
120+
// Return the console's width and height respectively
121+
unsigned int consoleWidth() {
122+
#if defined(LINUX) || defined(MAC)
123+
winsize conSize;
124+
ioctl(STDOUT_FILENO, TIOCGWINSZ, &conSize);
125+
return conSize.ws_col;
126+
#elif defined(WINDOWS)
127+
int width;
128+
CONSOLE_SCREEN_BUFFER_INFO csbi;
129+
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
130+
width = (int)(csbi.dwSize.X);
131+
return width;
132+
#endif
133+
}
134+
135+
unsigned int consoleHeight()
136+
137+
{
138+
#if defined(LINUX) || defined(MAC)
139+
winsize conSize;
140+
ioctl(STDOUT_FILENO, TIOCGWINSZ, &conSize);
141+
return conSize.ws_row;
142+
#elif defined(WINDOWS)
143+
int height;
144+
CONSOLE_SCREEN_BUFFER_INFO csbi;
145+
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
146+
height = (int)(csbi.dwSize.Y);
147+
return height;
148+
#endif
149+
}
150+
// Alias for the consoleWidth & consoleHeight funcs
151+
#define terminalWidth consoleWidth
152+
#define terminalHeight consoleHeight
153+
154+
// Another overload of decorateMe function with print to center ability
155+
void decorateMe(std::string textToDecor, unsigned short int lineBreaksNumber,
156+
std::string decorator, bool isCenter) {
157+
if (isCenter) {
158+
using namespace rang;
159+
160+
int charSize = textToDecor.capacity();
161+
162+
// Getting the terminal center value & starting point of the decorations
163+
unsigned int termCenter = consoleWidth() / 2;
164+
int startingPoint = termCenter - (charSize / 2);
165+
int textToDecor_StartingPoint = startingPoint + ((charSize * 2) - charSize);
166+
167+
std::cout << std::endl;
168+
std::cout << fg::red;
169+
std::cout << std::setw(startingPoint) << std::setfill(' ');
170+
for (int i = 0; i < (charSize * 2); i++) { std::cout << decorator; }
171+
std::cout << fg::reset;
172+
for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; }
173+
std::cout << fg::blue << style::bold << std::setw(textToDecor_StartingPoint)
174+
<< std::setfill(' ') << textToDecor << style::reset << fg::reset;
175+
176+
for (int i = 1; i <= lineBreaksNumber; i++) { std::cout << std::endl; }
177+
std::cout << fg::red;
178+
std::cout << std::setw(startingPoint) << std::setfill(' ');
179+
for (int i = 0; i < (charSize * 2); i++) { std::cout << decorator; }
180+
std::cout << fg::reset;
181+
std::cout << std::endl;
182+
std::cout << std::endl;
183+
} else {
184+
decorateMe(textToDecor, lineBreaksNumber, decorator);
185+
}
186+
}
187+
188+
} // end of namespace alib
189+
190+
// Undefining different platforms
191+
#undef LINUX
192+
#undef WINDOWS
193+
#undef MAC
194+
195+
#endif // ALIB_DOT_HPP

src/quickConvertSettings.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
1+
#include "rang.hpp"
22
#include "ffmpeg_coder.hpp"
33
#include <iostream>
44
#include <fstream>
55
#include <vector>
66
#include "quickConvertSettings.hpp"
7+
#include "alib.hpp"
8+
#include <iomanip>
79

810

911
void QC_Settings::set_setted_crf(){
@@ -27,16 +29,16 @@ void QC_Settings:: setDefault_encoding(){
2729
}else{
2830
default_encoding = "h264";
2931
}
30-
std::cout<<default_encoding;
3132
}
3233

3334
std::string QC_Settings:: getDefault_encoding(){
35+
setDefault_encoding();
3436
return default_encoding;
3537
}
3638

3739

3840
void QC_Settings::showOptions(){
39-
41+
clear_screen();
4042
std::vector<std::string> options;
4143
options.push_back("Set Default Encoding");
4244
options.push_back("Set default CRF");
@@ -48,7 +50,8 @@ void QC_Settings::showOptions(){
4850
}
4951

5052
// Taking user input
51-
std::cout<< "Choose your option:";
53+
std::cout<< rang::style::bold << rang::fg::blue << "\nChoose your option: "
54+
<< rang::style::reset << rang::fg::reset;
5255
std::cin >> userChoice;
5356
}
5457

@@ -61,6 +64,8 @@ try
6164

6265
if (qcsData.is_open()){
6366
qcsData << settings;
67+
68+
std::cout<<"\n|You preferred settings have been saved for future|";
6469
}
6570
else
6671
throw 501;
@@ -72,13 +77,13 @@ try
7277
}
7378

7479
void QC_Settings::default_encoding_configurer(){
80+
clear_screen();
7581
std::string givenEncoding;
7682
int selectedOption;
7783

7884
// Showing the current default encoding
79-
std::cout<< "The current default is: "<< default_encoding;
80-
std::cout<<std::endl;
81-
std::cout<<std::endl;
85+
std::string currentDef = "The current default is: "+default_encoding;
86+
alib::decorateMe(currentDef,1," ",true);
8287

8388
// Taking new encoding from user
8489
ffmpeg *fmpg = new ffmpeg();

0 commit comments

Comments
 (0)