2024-08-09 进度条ver.2,git

一、进度条

1、=> 样式进度条

process.c

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "process.h"

#define NUM 101
#define STYLE1 '>'
#define STYLE2 '='

// v1
void Process(){
  const char* label = "|/-\\";
  int len = strlen(label);
  char bar[NUM];
  memset(bar,'\0',sizeof(bar));
  int cnt = 0;
  while(cnt <= 100){
    bar[cnt] = STYLE1;
    printf("[%-100s][%d%%][%c]\r", bar, cnt, label[cnt%len]);
    fflush(stdout);
    usleep(50000);
    bar[cnt] = STYLE2;
    printf("[%-100s][%d%%][%c]\r", bar, cnt, label[cnt%len]);
    fflush(stdout);
    usleep(50000);
    cnt++;
  }
  printf("\r\n");
}

2、动态变化进度条

process.c

#include <stdio.h>
#include "process.h"
#include <string.h>
#include <unistd.h>

#define NUM 101
#define STYLE '#'
#define POINT '.'
#define SPACE ' '
const int pnum = 4;

// v2
void Process(double total, double cur){
  // 更新当前进度的百分比
  double rate = (cur/total) * 100;
  //printf("%.1lf%%\r", rate);
  //fflush(stdout);

  // 更新进度条主体
  char bar[NUM]; // 每 1% 更新一个等号
  memset(bar, '\0', sizeof(bar));
  int i;
  for(i = 0; i < (int)rate; i++){
    bar[i] = STYLE;
  }

  // 辅助变化符号
  static int num = 0;
  num++;
  num %= pnum;
  
  char points[pnum + 1];
  memset(points, '\0', sizeof(points));
  int j;
  for(j = 0; j < pnum; j++){
    if(j < num)
      points[j] = POINT;
    else 
      points[j] = SPACE;
  }

  // 打印
  printf("[%-100s][%.1lf%%]%s\r", bar, rate, points);
  fflush(stdout);
}

main.c

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include "process.h"

const int base = 20;
double total = 1024.0;
double once = 0.5;

void download(){
  double cur = 0.0;
  while(cur < total){
    // 模拟下载行为
    int r = rand() % base + 1;
    double speed = r * once;
    cur += speed;
    if(cur >= total)
      cur = total;
    usleep(40000);
    Process(total, cur);
    //printf("test: %.1lf %.1lf\r", cur, total);
    //fflush(stdout);
  }
  printf("\n");
}

int main(){
  srand(time(NULL));
  download();
  return 0;
}

二、git

1、引入

使用 Git 作为版本控制系统和 Gitee 作为代码托管平台,可以实现代码的备份与协作。

Git 是一种去中心化、分布式的版本控制系统,意味着每个开发者的本地仓库都完整包含了项目的全部历史记录,任何人都可以搭建自己的服务器来管理版本。

2、安装

# sudo yum install -y git

3、操作

当把源文件放入项目仓库中,默认它和 git 没有任何关系

(1)git clone

        获取远端仓库

(2)git status

        查看 git 仓库的状态

(3)git add

        把文件添加到 git 中(git 的暂存区)

(4)git commit -m ""

        提交记录有对应的 ID 值

(5)git push

        本地仓库和远端仓库的同步

4、细节补充

(1)配置 git log 中的用户名和邮箱(与 Gitee 保持一致)

(2).gitignore

        忽略掉 本地托管/不想上传 的文件

(3)要利用 git 提交,必须保证本地仓库和远端仓库内容一致

(4)在使用 Linux 和 Windows 并行开发并采用 Git 版本控制时,若同一文件被修改,则需使用 git pull 同步更改并手动解决可能产生的冲突(一般由组长或负责人处理)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值