Skip to content

Commit 49a58c7

Browse files
authored
tweak display
further tweaking display now the minimum width is 26
1 parent 5ac8742 commit 49a58c7

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

main.c

+37-15
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ static uint64_t passIndex = 0;
130130
static int passPhraseSize = 0;
131131
static int keyFileSize = 0;
132132

133-
char numberOfSegments;
134133
// _set_output_format(_TWO_DIGIT_EXPONENT);
135134

136135
/*
@@ -827,6 +826,25 @@ static inline void loadBar(int currentIteration, int maximalIteration, int numbe
827826
// numberOfSteps defines the number of times the bar updates.
828827
if ( currentIteration % (maximalIteration/numberOfSteps + 1) != 0 ) return;
829828

829+
830+
// adjust loadbar to display width
831+
struct winsize windowSize;
832+
char numberOfSegments;
833+
ioctl(STDOUT_FILENO, TIOCGWINSZ, &windowSize);
834+
numberOfSegments = windowSize.ws_col - 45;
835+
if(numberOfSegments < 4){
836+
numberOfSegments = windowSize.ws_col - 13;
837+
if (numberOfSegments < 4){
838+
numberOfSegments = 4;
839+
}
840+
}else{
841+
if(numberOfSegments > 50){
842+
numberOfSegments = 50;
843+
}
844+
// Start with the message
845+
printf("%s", startMessage);
846+
}
847+
830848
// Calculate the ratio of complete-to-incomplete.
831849
float ratio = (float) currentIteration / (float) maximalIteration;
832850
int loadBarCursorPosition = ratio * numberOfSegments;
@@ -837,9 +855,6 @@ static inline void loadBar(int currentIteration, int maximalIteration, int numbe
837855
elapsedTime = difftime(currentTime, startingTime);
838856
timeTillEnd = elapsedTime * (1.0/ratio - 1.0);
839857

840-
// Start with the message
841-
printf("%s", startMessage);
842-
843858
// Show the percentage.
844859
printf("%3d%% [", (int)(ratio*100));
845860

@@ -1202,6 +1217,23 @@ void checkArguments(int numberOfArgument, char* secondArgument){
12021217
}
12031218

12041219

1220+
/*
1221+
-void checkDisplaySize
1222+
1223+
check if display width is large enough
1224+
*/
1225+
void checkDisplaySize(){
1226+
struct winsize windowSize;
1227+
char numberOfSegments;
1228+
ioctl(STDOUT_FILENO, TIOCGWINSZ, &windowSize);
1229+
1230+
numberOfSegments = windowSize.ws_col - 45;
1231+
if(numberOfSegments < 4){
1232+
printf("The width of your display is too small for the loading bar to display properly.\nThe minimum size is %d and a size of %d is recommended\n", 45+4, 45+25);
1233+
}
1234+
}
1235+
1236+
12051237
/*
12061238
-void getOptionsAndKeyFile(char** arguments, int numberOfArgument, FILE** keyFile, char* filePosition, char* wantsToDeleteFirstFile)
12071239
arguments : this is argv (all the arguments given in terminal)
@@ -1775,19 +1807,9 @@ int main(int argc, char const *argv[])
17751807
char* tarName = NULL;
17761808
char* dirName = NULL;
17771809

1778-
struct winsize windowSize;
1779-
ioctl(STDOUT_FILENO, TIOCGWINSZ, &windowSize);
1780-
1781-
numberOfSegments = windowSize.ws_col - 45;
1782-
if(numberOfSegments < 4){
1783-
numberOfSegments = 4;
1784-
printf("The width of your display is too small for the loading bar to display properly.\nThe minimum size is %d and a size of %d is recommended\n", 45+4, 45+25);
1785-
}else if(numberOfSegments > 50){
1786-
numberOfSegments = 50;
1787-
}
1788-
17891810
setSecondarySeed();
17901811
getProgName((char*)argv[0]);
1812+
checkDisplaySize();
17911813
checkArguments(argc, (char*)argv[1]);
17921814
getOptionsAndKeyFile((char**)argv, argc, &keyFile, &filePosition, &wantsToDeleteFirstFile, &wantsToRandomizeFileName);
17931815

0 commit comments

Comments
 (0)