Exemplo n.º 1
0
void	add_char_input(t_shprop *shell, int key)
{
	t_term	*term;

	term = shell->term;
	if (ft_isprint(key))
	{
		ft_putchar_fd(key, term->fd);
		shell->input_len++;
		cur_pos_char_insert(shell, key);
		if (shell->hist && !shell->hist->prev)
			ft_str_renew(&(shell->hist)->line, ft_strdup(shell->input));
		shell->curs_pos++;
		if (shell->curs_pos >= (int)shell->input_len)
			if ((shell->curs_pos + shell->prompt_len) % term->ws.ws_col
					== 0)
			{
				T_PRINT(" ");
				key_move_left(shell);
				key_move_right(shell);
			}
		if (shell->input_len + shell->prompt_len > term->ws.ws_col
				&& shell->curs_pos < (int)shell->input_len)
			fill_lines(shell);
	}
}
Exemplo n.º 2
0
int		print_str_padded(char *str, t_vars *vars, char *prefix)
{
	size_t	len_str;
	int		padding;
	char	*string;

	string = ft_strdup(str);

	len_str = ft_strlen(string);
	padding = vars->padding - len_str;
	if (prefix)
		padding -= ft_strlen(prefix);
	if (padding > 0 && HAS_FLAG_ZERO(vars->flags))
		string = add_padding(string, (size_t)padding, vars);
	if (prefix)
		ft_str_renew(&string, ft_strjoin(prefix, string)); // not opti
	if (padding > 0 && !HAS_FLAG_ZERO(vars->flags))
		string = add_padding(string, (size_t)padding, vars);
	len_str = ft_strlen(string);
	ft_putstr(string);
	vars->precision = -1;
	return (len_str);
}