mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-27 11:13:24 +02:00
installer: Center root line and help line.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
@@ -176,9 +177,42 @@ int write_lang_configs(const char *lang) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char* get_system_release() {
|
||||||
|
char system_release[STRING_SIZE] = "\0";
|
||||||
|
|
||||||
|
FILE* f = fopen("/etc/system-release", "r");
|
||||||
|
if (f) {
|
||||||
|
fgets(system_release, sizeof(system_release), f);
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return strdup(system_release);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char* center_string(const char* str, int width) {
|
||||||
|
unsigned int str_len = strlen(str);
|
||||||
|
|
||||||
|
unsigned int indent_length = (width - str_len) / 2;
|
||||||
|
char indent[indent_length + 1];
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < indent_length; i++) {
|
||||||
|
indent[i] = ' ';
|
||||||
|
}
|
||||||
|
indent[indent_length] = '\0';
|
||||||
|
|
||||||
|
char* string = NULL;
|
||||||
|
if (asprintf(&string, "%s%s", indent, str) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
struct hw* hw = hw_init();
|
struct hw* hw = hw_init();
|
||||||
|
|
||||||
|
// Read /etc/system-release
|
||||||
|
char* system_release = get_system_release();
|
||||||
|
|
||||||
char discl_msg[40000] = "Disclaimer\n";
|
char discl_msg[40000] = "Disclaimer\n";
|
||||||
|
|
||||||
char *langnames[] = { "Deutsch", "English", "Français", "Español", "Nederlands", "Polski", "Русский", "Türkçe", NULL };
|
char *langnames[] = { "Deutsch", "English", "Français", "Español", "Nederlands", "Polski", "Русский", "Türkçe", NULL };
|
||||||
@@ -218,7 +252,16 @@ int main(int argc, char *argv[]) {
|
|||||||
newtInit();
|
newtInit();
|
||||||
newtCls();
|
newtCls();
|
||||||
|
|
||||||
newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN );
|
// Determine the size of the screen
|
||||||
|
int screen_cols = 0;
|
||||||
|
int screen_rows = 0;
|
||||||
|
|
||||||
|
newtGetScreenSize(&screen_cols, &screen_rows);
|
||||||
|
|
||||||
|
// Draw title
|
||||||
|
char* roottext = center_string(system_release, screen_cols);
|
||||||
|
newtDrawRootText(0, 0, roottext);
|
||||||
|
|
||||||
sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
|
sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
|
||||||
|
|
||||||
if (! (cmdfile = fopen("/proc/cmdline", "r")))
|
if (! (cmdfile = fopen("/proc/cmdline", "r")))
|
||||||
@@ -258,7 +301,8 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
setlocale(LC_ALL, shortlangnames[choice]);
|
setlocale(LC_ALL, shortlangnames[choice]);
|
||||||
|
|
||||||
newtPushHelpLine(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"));
|
char* helpline = center_string(_("<Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"), screen_cols);
|
||||||
|
newtPushHelpLine(helpline);
|
||||||
|
|
||||||
if (!unattended) {
|
if (!unattended) {
|
||||||
snprintf(message, sizeof(message),
|
snprintf(message, sizeof(message),
|
||||||
@@ -607,6 +651,10 @@ EXIT:
|
|||||||
newtFinished();
|
newtFinished();
|
||||||
|
|
||||||
// Free resources
|
// Free resources
|
||||||
|
free(system_release);
|
||||||
|
free(roottext);
|
||||||
|
free(helpline);
|
||||||
|
|
||||||
free(sourcedrive);
|
free(sourcedrive);
|
||||||
|
|
||||||
if (destination) {
|
if (destination) {
|
||||||
|
|||||||
Reference in New Issue
Block a user