Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/smart-fetch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# smart-fetch

Smart-fetch is a command-line system information tool written in c. Smart-fetch displays information about your operating system, software and hardware in an aesthetic and virsually pleasing way.

Smart-fetch is currently an initial version, but it will be more feature-rich in the future.See the help information for instructions.**smart-fetch -h**
270 changes: 270 additions & 0 deletions apps/smart-fetch/smart_fetch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
/*
* Copyright (c) 2023, Real-Thread Technology Co., Ltd
*
* SPDX-License-Identifier: GPL-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-06 Mr'Zhou the first version
*/

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/utsname.h>
#include <sys/statfs.h>
#include <sys/sysinfo.h>
#include "smart_fetch.h"
#include <string.h>

static void smart_fetch_print_info()
{
printf("\033[20A \n");
printf(RED " %s time: " NONE BLUE "%d-%d-%d " NONE GREEN "%d:%d:%d\n" NONE, RIGHT_MOVE, (1900 + smart_p->tm_year), ( 1 + smart_p->tm_mon), smart_p->tm_mday, (smart_p->tm_hour + 12), smart_p->tm_min, smart_p->tm_sec);
printf("%s %s sysname: " NONE "%s %s" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_info.sysname);
printf("%s %s nodename: " NONE "%s %s" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_info.nodename);
printf("%s %s release: " NONE "%s %s" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_info.release);
printf("%s %s version: " NONE "%s %s" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_info.version);
printf("%s %s machine: " NONE "%s %s" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_info.machine);
printf("%s %s domainname: " NONE "%s %s" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_info.__domainname);
printf("%s %s f_bsize: " NONE "%s %u" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_block.f_bsize);
printf("%s %s f_blocks: " NONE "%s %u" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_block.f_blocks);
printf("%s %s f_bfree: " NONE "%s %u" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_block.f_bfree);
printf("%s %s f_bavail: " NONE "%s %u" NONE "\n",RIGHT_MOVE, smart_title_color, smart_info_color, smart_sys_block.f_bavail);
printf("%s \n", RIGHT_MOVE);
printf("%s \n", RIGHT_MOVE);
printf("%s \n", RIGHT_MOVE);
printf("%s \n", RIGHT_MOVE);
printf("%s " RED "github id:" NONE FONT_FLICKER GREEN GITHUB_ID NONE "\n", RIGHT_MOVE);
printf("%s \n", RIGHT_MOVE);
printf(" %s" FONT_FLICKER BG_BLACK " " BG_RED " " BG_GREEN " " BG_YELLOW " " BG_BLUE " " BG_PURPLE " " BG_CYAN " " BG_WHITE " " NONE "\n", RIGHT_MOVE );
printf(" %s" BG_BLACK " " BG_RED " " BG_GREEN " " BG_YELLOW " " BG_BLUE " " BG_PURPLE " " BG_CYAN " " BG_WHITE " " NONE "\n", RIGHT_MOVE);

}

static void smart_fetch_print_logo()
{
printf("\n \
\e[0;31m.oyssssssssssssssssssssssssssy+.\e[0m \n \
\e[0;31m/yossssssss\e[0mrrrr\e[0;31msssss\e[0mrrrr\e[0;31msssssssoy+\e[0m \n \
\e[0;31m:h/sssssssss\e[0mrrrr\e[0;31msss\e[0mrrrr\e[0;31msssssssssh+-\e[0m \n \
\e[0;31mys.ssssssssss\e[0mrrrrrrr\e[0;31msssssssssssssss+-p\e[0m \n \
\e[0;31mh+-sssssssssss\e[0mrrrr\e[0;31msssssssssssssssssss:h/\e[0m \n \
\e[0;31mh+-ssssssssssss\e[0mrrrr\e[0;31mssssssssssssssssssss+a'\e[0m \n \
\e[0;31m/dmsssssssssssss\e[0mrrrr\e[0;31msssssssssssssssssssssz8`\e[0m \n \
\e[0;31mc/ysssssssssssssss\e[0m\e[5m\e[3;32mrt-thread\e[0m\e[0;31mssssssssssssssss-f'\e[0m \n \
\e[0;31mp/osssss\e[0mttttttttttttt\e[0;31mssssss\e[0mtttttttttttt\e[0;31msssss+j;\e[0m \n \
\e[0;31mp/osssss\e[0mttttttttttttt\e[0;31mssssss\e[0mttttttttttttt\e[0;31msssss+j;\e[0m \n \
\e[0;31mc/yssssssss\e[0mttttt\e[0;31mssssssssssssss\e[0mttttt\e[0;31mssssssss-k/\e[0m \n \
\e[0;31m/dmssssssss\e[0mttttt\e[0;31mssssssssssssss\e[0mttttt\e[0;31msssssss*c'\e[0m \n \
\e[0;31mh+-sssssss\e[0mttttt\e[0;31mssssssssssssss\e[0mttttt\e[0;31mssssss+a'\e[0m \n \
\e[0;31mh+-ssssss\e[0mttttt\e[0;31mssssssssssssss\e[0mttttt\e[0;31msssss:h/\e[0m \n \
\e[0;31mys.sssss\e[0mttttt\e[0;31mssssssssssssss\e[0mttttt\e[0;31mssss+-p\e[0m \n \
\e[0;31m:h/ssss\e[0mttttt\e[0;31mssssssssssssss\e[0mttttt\e[0;31msssh+-\e[0m \n \
\e[0;31m/yosssssssssssssssssssssssssssssoy+\e[0m \n \
\e[0;31m.oysssssssssssssssssssssssssssy+.\e[0m \n \
");
}

void smart_fetch_get_time()
{
time_t timep;
time(&timep);
smart_p = localtime(&timep);
}

int smart_fetch_get_utsname()
{
memset(&smart_sys_info, '\0', sizeof(smart_sys_info));
if(uname(&smart_sys_info) != -1)
{
return SUCCESS_SYS_INFO;
}
return ERROR_SYS_INFO;
}

int smart_fetch_get_statfs()
{
if(statfs(smart_sys_path,&smart_sys_block) != -1)
{
return SUCCESS_SYS_INFO;
}
return ERROR_SYS_INFO;
}

int smart_fetch_get_memory()
{
char buffer[1024];
FILE *fp;
fp = popen("free", "r");
if(fp < 0)
{
return ;
}
while(fgets(buffer , sizeof(buffer), fp) != NULL)
{
printf("%s", buffer);
}
pclose(fp);
return SUCCESS_SYS_INFO;
}

static void smart_fetch_color_parser(int b_font,char *t_color)
{
char color[16];
if(t_color == NULL)
{
return ;
}
memset(color, '\0', sizeof(color));
if(smart_bold_font != 0)
{
if((strcmp(t_color,"BLACK")) == 0)
{
strcpy(color,L_BLACK);
}
else if((strcmp(t_color,"RED")) == 0)
{
strcpy(color,L_RED);
}
else if((strcmp(t_color,"GREEN")) == 0)
{
strcpy(color,L_GREEN);
}
else if((strcmp(t_color,"YELLOW")) == 0)
{
strcpy(color,YELLOW);
}
else if((strcmp(t_color,"BLUE")) == 0)
{
strcpy(color,L_BLUE);
}
else if((strcmp(t_color,"PURPLE")) == 0)
{
strcpy(color,L_PURPLE);
}
else if((strcmp(t_color,"CYAN")) == 0)
{
strcpy(color,L_CYAN);
}
else if((strcmp(t_color,"WHITE")) == 0)
{
strcpy(color,WHITE);
}
else
{
strcpy(color,L_RED);
}

}
else
{
if((strcmp(t_color,"BLACK")) == 0)
{
strcpy(color,BLACK);
}
else if((strcmp(t_color,"RED")) == 0)
{
strcpy(color,RED);
}
else if((strcmp(t_color,"GREEN")) == 0)
{
strcpy(color,GREEN);
}
else if((strcmp(t_color,"YELLOW")) == 0)
{
strcpy(color,BROWN);
}
else if((strcmp(t_color,"BLUE")) == 0)
{
strcpy(color,BLUE);
}
else if((strcmp(t_color,"PURPLE")) == 0)
{
strcpy(color,PURPLE);
}
else if((strcmp(t_color,"CYAN")) == 0)
{
strcpy(color,CYAN);
}
else if((strcmp(t_color,"WHITE")) == 0)
{
strcpy(color,GRAY);
}
else
{
strcpy(color,GREEN);
}
}
memset(t_color, '\0', sizeof(t_color));
strcpy(t_color, color);
}

static void smart_fetch_color_deal()
{
smart_fetch_color_parser(smart_bold_font, smart_title_color);
smart_fetch_color_parser(smart_bold_font, smart_info_color);
}

static void smart_fetch_help()
{
printf("\t\tsmart_fetch help\n");
printf("\t\t cmd\texplain\n");
printf("\t\t -t \t:update titile color\n");
printf("\t\t -c \t:update information color\n");
printf("\t\t -d \t:disable info\n");
printf("\t\t -b \t:blod font\n");
printf("\t\t example : smart-fetch -b -c YELLOW -t GREEN \n");
}

int smart_fetch_param_parser(int argc, char **argv)
{
char *opt;
int idx;
if (argc < 1)
{
return SUCCESS_SYS_INFO;
}
memset(smart_title_color, '\0', sizeof(smart_title_color));
memset(smart_info_color, '\0', sizeof(smart_info_color));
while((idx = getopt_long(argc, argv, smart_short_option, smart_long_option, NULL)) != EOF)
{
switch(idx)
{
case 't' :
opt = optarg;
strcpy(smart_title_color, opt);
break;
case 'c' :
opt = optarg;
strcpy(smart_info_color, opt);
break;
case 'd' :
opt = optarg;
break;
case 'b' :
smart_bold_font = 1;
break;
case 'h' :
smart_fetch_help();
return ;
default :
break;
}
}
smart_fetch_color_deal();
smart_fetch_get_time();
smart_fetch_get_utsname();
smart_fetch_get_statfs();
smart_fetch_print_logo();
smart_fetch_print_info();
return SUCCESS_SYS_INFO;
}

int main(int argc, char **argv)
{
smart_fetch_param_parser(argc, argv);
return 0;
}
76 changes: 76 additions & 0 deletions apps/smart-fetch/smart_fetch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2023, Real-Thread Technology Co., Ltd
*
* SPDX-License-Identifier: GPL-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-06 Bernard the first version
*/

#ifndef SMART_FETCH_H__
#define SMART_FETCH_H__

#define ERROR_SYS_INFO -1
#define SUCCESS_SYS_INFO 0

#define NONE "\e[0m"
#define BLACK "\e[0;30m"
#define L_BLACK "\e[1;30m"
#define RED "\e[0;31m"
#define L_RED "\e[1;31m"
#define GREEN "\e[0;32m"
#define L_GREEN "\e[1;32m"
#define BROWN "\e[0;33m"
#define YELLOW "\e[1;33m"
#define BLUE "\e[0;34m"
#define L_BLUE "\e[1;34m"
#define PURPLE "\e[0;35m"
#define L_PURPLE "\e[1;35m"
#define CYAN "\e[0;36m"
#define L_CYAN "\e[1;36m"
#define GRAY "\e[0;37m"
#define WHITE "\e[1;37m"

#define BG_BLACK "\e[40m"
#define BG_RED "\e[41m"
#define BG_GREEN "\e[42m"
#define BG_YELLOW "\e[43m"
#define BG_BLUE "\e[44m"
#define BG_PURPLE "\e[45m"
#define BG_CYAN "\e[46m"
#define BG_WHITE "\e[47m"

#define BOLD "\e[1m"
#define UNDERLINE "\e[4m"
#define BLINK "\e[5m"
#define REVERSE "\e[7m"
#define HIDE "\e[8m"
#define CLEAR "\e[2J"
#define CLRLINE "\r\e[K"

#define RIGHT_MOVE "\e[60C"
#define FONT_FLICKER "\e[5m"

#define GITHUB_ID "zmq810150896"
const struct option smart_long_option[] =
{
"title_color", 1, NULL, 't',
"info_color", 1, NULL, 'c',
"disable", 1, NULL, 'd',
"bold", 0, NULL, 'b',
"help", 0, NULL, 'h',
{NULL, 0, NULL, 0}
};

struct statfs smart_sys_block;
struct utsname smart_sys_info;
struct tm *smart_p;

const char const *smart_short_option = "t:c:d:bh";
int smart_bold_font = 0;
char smart_title_color[16]=RED;
char smart_info_color[16]=GREEN;
char smart_sys_path[256] = "/";

#endif /*__SMART_FETCH_H__*/
31 changes: 31 additions & 0 deletions apps/smart-fetch/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Licensed under the Apache License, Version 2.0 (the "License");
-- You may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2022-2023 RT-Thread Development Team
--
-- @author zhouquan
-- @file xmake.lua
--
-- Change Logs:
-- Date Author Notes
-- ------------ ---------- -----------------------------------------------
-- 2023-03-10 zhouquan initial version
--
add_rules("mode.debug", "mode.release")

target("smart-fetch")
do
add_includedirs("./")
add_files("*.c")
end
target_end()