library/src/terminal/BP-LinuxTerminal.cc
// Gets information about the terminal which is currently being used.
Gets information about the terminal which is currently being used.
Gets information about the terminal which is currently being used .
P_BP_LINUX_TERMINAL_INFO BP_CreateCurrentTerminalInformationLinux()
{
	P_BP_LINUX_TERMINAL_INFO terminal_info = (P_BP_LINUX_TERMINAL_INFO) bpcalloc(sizeof(BP_LINUX_TERMINAL_INFO), 1);
	if(!terminal_info)
		return NULL;
	terminal_info->tq = BP_CreateLinkL("terminfo", BP_FALSE);
	if(isatty(0))
		terminal_info->file_descriptor_is_tty = BP_TRUE;
	char *tty_name = ttyname(0);
	if(tty_name)
		terminal_info->tty_name = tq_strndup(terminal_info->tq, tty_name, 1024, BPLN);
	terminal_info->is_current_terminal = BP_TRUE;
	ioctl(0, TIOCGWINSZ, &terminal_info->w);
	if(tcgetattr(0, &terminal_info->termios_info) == 0)
		terminal_info->termios_retrieved_successfully = BP_TRUE;
	return terminal_info;
}
P_BP_LINUX_TERMINAL_INFO BP_CreateCurrentTerminalInformationLinux ( ) { P_BP_LINUX_TERMINAL_INFO terminal_info = ( P_BP_LINUX_TERMINAL_INFO ) bpcalloc ( sizeof ( BP_LINUX_TERMINAL_INFO ) , 1 ) ; if ( ! terminal_info ) return NULL ; terminal_info -> tq = BP_CreateLinkL ( " " , BP_FALSE ) ; if ( isatty ( 0 ) ) terminal_info -> file_descriptor_is_tty = BP_TRUE ; char * tty_name = ttyname ( 0 ) ; if ( tty_name ) terminal_info -> tty_name = tq_strndup ( terminal_info -> tq , tty_name , 1024 , BPLN ) ; terminal_info -> is_current_terminal = BP_TRUE ; ioctl ( 0 , TIOCGWINSZ , & terminal_info -> w ) ; if ( tcgetattr ( 0 , & terminal_info -> termios_info ) == 0 ) terminal_info -> termios_retrieved_successfully = BP_TRUE ; return terminal_info ; }
Gets information about the terminal which is currently being used.
Gets information about the terminal which is currently being used .
// attempt to create space for the terminal information // create a new linkl for allocations // set this if we've determined that the file descriptor is a tty // get the tty name // set the info flag to true // attempt to get terminal information via ioctl // attempt to get termios information, set flag if we got the info ok // return the terminal information