Ejemplo n.º 1
0
void
key_up()
{
	// UP - scroll files
	if (file_list.cur_idx > file_list.head_idx) {
		file_list.cur_idx -= 1;
		//file_list.tail_idx -= 1;
		show_files(main_win);
		return;
	}
	if (file_list.cur_idx == file_list.head_idx &&
			file_list.head_idx > 0) {
		file_list.head_idx -= 1;
		file_list.tail_idx -= 1;
		file_list.cur_idx -= 1;
		show_files(main_win);
	}
}
Ejemplo n.º 2
0
void
key_down()
{
	// DOWN - scroll files
	if (file_list.cur_idx < file_list.contents->amount - 1 &&
			file_list.cur_idx < file_list.tail_idx) {
		file_list.cur_idx += 1;
		show_files(main_win);
		return;
	}

	if (file_list.cur_idx < file_list.contents->amount - 1 &&
			file_list.cur_idx == file_list.tail_idx) {
		file_list.cur_idx += 1;
			file_list.head_idx += 1;
			file_list.tail_idx += 1;
			show_files(main_win);
	}
}
Ejemplo n.º 3
0
int
curses_ui()
{
	int err;

	err = ui_init();
	if (err == -1) {
		return (-1);
	}

	file_list.dir_name = malloc(MAXPATHLEN + 1);
	if (!file_list.dir_name) {
		mvwprintw(main_win, 0, 1, "ERROR: Can't initialize dir_name.");
		wrefresh(main_win);
		return (-1);
	}
	err = first_run_file_list(main_win);
	if (err == -1) {
		mvwprintw(main_win, 0, 1, "ERROR: Can't initialize file list.");
		wrefresh(main_win);
		return (-1);
	}

	sock_fd = get_client_socket();

	err = pthread_create(&receiver_thread, rcv_attr, ui_socket_receiver, rcv_arg);
	if (err != 0) {
		mvwprintw(main_win, 0, 1, "ERROR: receiver thread");
		wrefresh(main_win);
		return (-1);
	}

	show_files(main_win);
	curses_loop();

	// wait for receiver_thread if alive
	if (pthread_kill(receiver_thread, 0) == 0) {
		printw("UI: waiting for receiver_thread..");
		refresh();
		pthread_join(receiver_thread, NULL);
	}

	free_dir_list();
	free(file_list.dir_name);

	ui_cleanup();
	return (0);
}
Ejemplo n.º 4
0
void
resize_windows()
{
	struct window_dimensions *dimensions;

	set_status_window_size();
	dimensions = status_win_dimensions;
	wresize(status_win, dimensions->height, dimensions->width);
	mvwin(status_win, dimensions->starty, dimensions->startx);
	wclear(status_win);
	box(status_win, 0, 0);
	show_status();
	wrefresh(status_win);

	set_main_window_size();
	dimensions = main_win_dimensions;
	wresize(main_win, dimensions->height, dimensions->width);
	handle_resize(main_win);
	show_files(main_win);
}
Ejemplo n.º 5
0
int
change_directory(char *dir)
{
	int err, y, x;

	if (chdir(dir) == -1) {
		mvwprintw(status_win, 3, 1, "can't change dir: %s", dir);
		return (-1);
	}

	if (getcwd(file_list.dir_name, MAXPATHLEN) == 0) {
		mvwprintw(status_win, 3, 1, "can't get current directory");
		return (-1);
	}

	// reset cursor/file position after changing directory
	file_list.cur_idx = 0;

	// clean up old list
	free_dir_list();

	// allocate new list
	init_list_for_dir();

	//populate list with file/directory names
	err = scan_dir(file_list.contents, false, false);
	if (err == -1) {
		mvwprintw(status_win, 1, 1, "ERROR in change_directory()");
		wrefresh(status_win);
		return (-1);
	}

	getmaxyx(main_win, y, x);

	file_list.head_idx = 0;
	file_list.tail_idx = y - 3;
	file_list.cur_idx = 0;

	show_files(main_win);
	return (0);
}
Ejemplo n.º 6
0
static void	bg_process(char *dir, t_gen *gen)
{
  int		i;
  DIR		*ptr_dir;
  char		**rec;

  rec = NULL;
  if ((ptr_dir = try_open_dir(dir, gen)))
    {
      try_read_dir(ptr_dir, dir, gen);
      closedir(ptr_dir);
    }
  show_files(gen);
  rec = set_folder_recursive(gen->elem, gen->opts);
  gen->elem = free_list(gen->elem);
  my_putchar('\n');
  for (i = 0; rec && rec[i]; i++)
    {
      bg_process(rec[i], gen);
      free(rec[i]);
    }
  if (rec)
    free(rec);
}
Ejemplo n.º 7
0
void root_page(void)
{
	int8_t root_page_index = 0;
	int8_t page_reflash = 1;

	sysParam.delay = 10;
	sysParam.interval = 10;
	sysParam.uartFlag = 0;
	sysParam.GRB[0] = 1;
	sysParam.GRB[1] = 1;
	sysParam.GRB[2] = 1;
	sysParam.start = 0;
	sysParam.end = 8;

	while(1)
	{
		if(page_reflash)
		{
			page_reflash = 0;
			LCD_Clear(BLACK);
			
			LCD_DrawRectangle(0, 0, 127, 127, YELLOW);
			LCD_ShowString(1, 1,  (char *)"     PIXELSTICK      ", BLACK, YELLOW);
			
			if(SD_Init() != SD_OK)	//初始化失败
				LCD_ShowString(10, 16, (char *)"SD Card", RED, BLACK);
			else	//初始化成功了
				LCD_ShowString(10, 16, (char *)"SD Card", GREEN, BLACK);	

			LCD_ShowString(10, 32, (char *)"Wifi", RED, BLACK);
			LCD_ShowString(10, 48, (char *)"Lamp", WHITE, BLACK);
			LCD_ShowString(10, 64, (char *)"Settings", WHITE, BLACK);
			LCD_ShowString(10, 80, (char *)"About Me", WHITE, BLACK);
			LCD_ShowString(10, 96, (char *)"Gradient Ramp", WHITE, BLACK);
		}
		
		LCD_ShowIcon(2, 16 +root_page_index*16, 0, RED, BLACK);	//先清除之前的光标

		/* button LEFT */
		if(button_state[LEFT] == BUTTON_PRESS_UP)
		{
			button_state[LEFT] = BUTTON_NOT_PRESSED;
			;
		}

		/* button RIGHT */
		if(button_state[RIGHT] == BUTTON_PRESS_UP)
		{
			button_state[RIGHT] = BUTTON_NOT_PRESSED;
			;
		}

		/* button UP */
		if(button_state[UP] == BUTTON_PRESS_UP)
		{
			button_state[UP] = BUTTON_NOT_PRESSED;

			root_page_index--;
			if(root_page_index < 0)
				root_page_index = ROOT_PAGE_OPTION_NUM - 1;
		}

		/* button DOWN */
		if(button_state[DOWN] == BUTTON_PRESS_UP)
		{
			button_state[DOWN] = BUTTON_NOT_PRESSED;

			root_page_index++;
			if(root_page_index == ROOT_PAGE_OPTION_NUM)
				root_page_index = 0;
		}

		LCD_ShowIcon(2, 16+root_page_index*16, 2, WHITE, BLACK);

		/* button MIDDLE */
		if(button_state[MIDDLE] == BUTTON_PRESS_UP)	//选中或者确认
		{
			button_state[MIDDLE] = BUTTON_NOT_PRESSED;

			switch(root_page_index)
			{
				case SD_CARD_PAGE:	/* SD card browser */
					show_files();
					page_reflash = 1;
					break;
								
				case WIFI_PAGE:	/* esp8266 settings */
					wifi_page();
					page_reflash = 1;
					break;
				
				case LAMP_PAGE:	/* param settings */
					lamp_page();
					page_reflash = 1;
					break;

				case SETTING_PAGE:	/* param settings */
					setting_page();
					page_reflash = 1;
					break;

				case INFO_PAGE:	/* informations */
					info_page();
					page_reflash = 1;
					break;
				
				case GRADIENT_RAMP_PAGE:	/* informations */
					gradient_ramp_page();
					page_reflash = 1;
					break;
				
				default:
					break;
			}
		}
		
		delay_ms(20);
	}
}
Ejemplo n.º 8
0
int cmd_ls_files(int argc, const char **argv, const char *prefix)
{
	int i;
	int exc_given = 0, require_work_tree = 0;
	struct dir_struct dir;

	memset(&dir, 0, sizeof(dir));
	if (prefix)
		prefix_offset = strlen(prefix);
	git_config(git_default_config, NULL);

	for (i = 1; i < argc; i++) {
		const char *arg = argv[i];

		if (!strcmp(arg, "--")) {
			i++;
			break;
		}
		if (!strcmp(arg, "-z")) {
			line_terminator = 0;
			continue;
		}
		if (!strcmp(arg, "-t") || !strcmp(arg, "-v")) {
			tag_cached = "H ";
			tag_unmerged = "M ";
			tag_removed = "R ";
			tag_modified = "C ";
			tag_other = "? ";
			tag_killed = "K ";
			if (arg[1] == 'v')
				show_valid_bit = 1;
			continue;
		}
		if (!strcmp(arg, "-c") || !strcmp(arg, "--cached")) {
			show_cached = 1;
			continue;
		}
		if (!strcmp(arg, "-d") || !strcmp(arg, "--deleted")) {
			show_deleted = 1;
			continue;
		}
		if (!strcmp(arg, "-m") || !strcmp(arg, "--modified")) {
			show_modified = 1;
			require_work_tree = 1;
			continue;
		}
		if (!strcmp(arg, "-o") || !strcmp(arg, "--others")) {
			show_others = 1;
			require_work_tree = 1;
			continue;
		}
		if (!strcmp(arg, "-i") || !strcmp(arg, "--ignored")) {
			dir.show_ignored = 1;
			require_work_tree = 1;
			continue;
		}
		if (!strcmp(arg, "-s") || !strcmp(arg, "--stage")) {
			show_stage = 1;
			continue;
		}
		if (!strcmp(arg, "-k") || !strcmp(arg, "--killed")) {
			show_killed = 1;
			require_work_tree = 1;
			continue;
		}
		if (!strcmp(arg, "--directory")) {
			dir.show_other_directories = 1;
			continue;
		}
		if (!strcmp(arg, "--no-empty-directory")) {
			dir.hide_empty_directories = 1;
			continue;
		}
		if (!strcmp(arg, "-u") || !strcmp(arg, "--unmerged")) {
			/* There's no point in showing unmerged unless
			 * you also show the stage information.
			 */
			show_stage = 1;
			show_unmerged = 1;
			continue;
		}
		if (!strcmp(arg, "-x") && i+1 < argc) {
			exc_given = 1;
			add_exclude(argv[++i], "", 0, &dir.exclude_list[EXC_CMDL]);
			continue;
		}
		if (!prefixcmp(arg, "--exclude=")) {
			exc_given = 1;
			add_exclude(arg+10, "", 0, &dir.exclude_list[EXC_CMDL]);
			continue;
		}
		if (!strcmp(arg, "-X") && i+1 < argc) {
			exc_given = 1;
			add_excludes_from_file(&dir, argv[++i]);
			continue;
		}
		if (!prefixcmp(arg, "--exclude-from=")) {
			exc_given = 1;
			add_excludes_from_file(&dir, arg+15);
			continue;
		}
		if (!prefixcmp(arg, "--exclude-per-directory=")) {
			exc_given = 1;
			dir.exclude_per_dir = arg + 24;
			continue;
		}
		if (!strcmp(arg, "--exclude-standard")) {
			exc_given = 1;
			setup_standard_excludes(&dir);
			continue;
		}
		if (!strcmp(arg, "--full-name")) {
			prefix_offset = 0;
			continue;
		}
		if (!strcmp(arg, "--error-unmatch")) {
			error_unmatch = 1;
			continue;
		}
		if (!prefixcmp(arg, "--with-tree=")) {
			with_tree = arg + 12;
			continue;
		}
		if (!prefixcmp(arg, "--abbrev=")) {
			abbrev = strtoul(arg+9, NULL, 10);
			if (abbrev && abbrev < MINIMUM_ABBREV)
				abbrev = MINIMUM_ABBREV;
			else if (abbrev > 40)
				abbrev = 40;
			continue;
		}
		if (!strcmp(arg, "--abbrev")) {
			abbrev = DEFAULT_ABBREV;
			continue;
		}
		if (*arg == '-')
			usage(ls_files_usage);
		break;
	}

	if (require_work_tree && !is_inside_work_tree())
		setup_work_tree();

	pathspec = get_pathspec(prefix, argv + i);

	/* Verify that the pathspec matches the prefix */
	if (pathspec)
		prefix = verify_pathspec(prefix);

	/* Treat unmatching pathspec elements as errors */
	if (pathspec && error_unmatch) {
		int num;
		for (num = 0; pathspec[num]; num++)
			;
		ps_matched = xcalloc(1, num);
	}

	if (dir.show_ignored && !exc_given) {
		fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
			argv[0]);
		exit(1);
	}

	/* With no flags, we default to showing the cached files */
	if (!(show_stage | show_deleted | show_others | show_unmerged |
	      show_killed | show_modified))
		show_cached = 1;

	read_cache();
	if (prefix)
		prune_cache(prefix);
	if (with_tree) {
		/*
		 * Basic sanity check; show-stages and show-unmerged
		 * would not make any sense with this option.
		 */
		if (show_stage || show_unmerged)
			die("ls-files --with-tree is incompatible with -s or -u");
		overlay_tree_on_cache(with_tree, prefix);
	}
	show_files(&dir, prefix);

	if (ps_matched) {
		int bad;
		bad = report_path_error(ps_matched, pathspec, prefix_offset);
		if (bad)
			fprintf(stderr, "Did you forget to 'git add'?\n");

		return bad ? 1 : 0;
	}

	return 0;
}
Ejemplo n.º 9
0
int cmd_ls_files(int argc, const char **argv, const char *prefix)
{
	int require_work_tree = 0, show_tag = 0;
	struct dir_struct dir;
	struct option builtin_ls_files_options[] = {
		{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
			"paths are separated with NUL character",
			PARSE_OPT_NOARG, option_parse_z },
		OPT_BOOLEAN('t', NULL, &show_tag,
			"identify the file status with tags"),
		OPT_BOOLEAN('v', NULL, &show_valid_bit,
			"use lowercase letters for 'assume unchanged' files"),
		OPT_BOOLEAN('c', "cached", &show_cached,
			"show cached files in the output (default)"),
		OPT_BOOLEAN('d', "deleted", &show_deleted,
			"show deleted files in the output"),
		OPT_BOOLEAN('m', "modified", &show_modified,
			"show modified files in the output"),
		OPT_BOOLEAN('o', "others", &show_others,
			"show other files in the output"),
		OPT_BIT('i', "ignored", &dir.flags,
			"show ignored files in the output",
			DIR_SHOW_IGNORED),
		OPT_BOOLEAN('s', "stage", &show_stage,
			"show staged contents' object name in the output"),
		OPT_BOOLEAN('k', "killed", &show_killed,
			"show files on the filesystem that need to be removed"),
		OPT_BIT(0, "directory", &dir.flags,
			"show 'other' directories' name only",
			DIR_SHOW_OTHER_DIRECTORIES),
		OPT_NEGBIT(0, "empty-directory", &dir.flags,
			"don't show empty directories",
			DIR_HIDE_EMPTY_DIRECTORIES),
		OPT_BOOLEAN('u', "unmerged", &show_unmerged,
			"show unmerged files in the output"),
		OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
			    "show resolve-undo information"),
		{ OPTION_CALLBACK, 'x', "exclude", &dir.exclude_list[EXC_CMDL], "pattern",
			"skip files matching pattern",
			0, option_parse_exclude },
		{ OPTION_CALLBACK, 'X', "exclude-from", &dir, "file",
			"exclude patterns are read from <file>",
			0, option_parse_exclude_from },
		OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, "file",
			"read additional per-directory exclude patterns in <file>"),
		{ OPTION_CALLBACK, 0, "exclude-standard", &dir, NULL,
			"add the standard git exclusions",
			PARSE_OPT_NOARG, option_parse_exclude_standard },
		{ OPTION_SET_INT, 0, "full-name", &prefix_offset, NULL,
			"make the output relative to the project top directory",
			PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL },
		OPT_BOOLEAN(0, "error-unmatch", &error_unmatch,
			"if any <file> is not in the index, treat this as an error"),
		OPT_STRING(0, "with-tree", &with_tree, "tree-ish",
			"pretend that paths removed since <tree-ish> are still present"),
		OPT__ABBREV(&abbrev),
		OPT_END()
	};

	memset(&dir, 0, sizeof(dir));
	if (prefix)
		prefix_offset = strlen(prefix);
	git_config(git_default_config, NULL);

	if (read_cache() < 0)
		die("index file corrupt");

	argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
			ls_files_usage, 0);
	if (show_tag || show_valid_bit) {
		tag_cached = "H ";
		tag_unmerged = "M ";
		tag_removed = "R ";
		tag_modified = "C ";
		tag_other = "? ";
		tag_killed = "K ";
		tag_skip_worktree = "S ";
		tag_resolve_undo = "U ";
	}
	if (show_modified || show_others || show_deleted || (dir.flags & DIR_SHOW_IGNORED) || show_killed)
		require_work_tree = 1;
	if (show_unmerged)
		/*
		 * There's no point in showing unmerged unless
		 * you also show the stage information.
		 */
		show_stage = 1;
	if (dir.exclude_per_dir)
		exc_given = 1;

	if (require_work_tree && !is_inside_work_tree())
		setup_work_tree();

	pathspec = get_pathspec(prefix, argv);

	/* be nice with submodule paths ending in a slash */
	if (pathspec)
		strip_trailing_slash_from_submodules();

	/* Verify that the pathspec matches the prefix */
	if (pathspec)
		prefix = verify_pathspec(prefix);

	/* Treat unmatching pathspec elements as errors */
	if (pathspec && error_unmatch) {
		int num;
		for (num = 0; pathspec[num]; num++)
			;
		ps_matched = xcalloc(1, num);
	}

	if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given)
		die("ls-files --ignored needs some exclude pattern");

	/* With no flags, we default to showing the cached files */
	if (!(show_stage | show_deleted | show_others | show_unmerged |
	      show_killed | show_modified | show_resolve_undo))
		show_cached = 1;

	if (prefix)
		prune_cache(prefix);
	if (with_tree) {
		/*
		 * Basic sanity check; show-stages and show-unmerged
		 * would not make any sense with this option.
		 */
		if (show_stage || show_unmerged)
			die("ls-files --with-tree is incompatible with -s or -u");
		overlay_tree_on_cache(with_tree, prefix);
	}
	show_files(&dir, prefix);
	if (show_resolve_undo)
		show_ru_info(prefix);

	if (ps_matched) {
		int bad;
		bad = report_path_error(ps_matched, pathspec, prefix_offset);
		if (bad)
			fprintf(stderr, "Did you forget to 'git add'?\n");

		return bad ? 1 : 0;
	}

	return 0;
}