示例#1
0
static void
setmod(int newmode)
{
	if (!iflag)
	{
		if (curmode != NORMAL && newmode != NORMAL)
			setmod(NORMAL);
		switch (newmode) {
		case NORMAL:
			switch(curmode) {
			case NORMAL:
				break;
			case UNDERL:
				put(exit_underline_mode);
				break;
			default:
				/* This includes standout */
				put(exit_attribute_mode);
				break;
			}
			break;
		case ALTSET:
	/*
	 * Note that we use REVERSE for the alternate character set,
	 * not the as/ae capabilities.  This is because we are modelling
	 * the model 37 teletype (since that's what nroff outputs) and
	 * the typical as/ae is more of a graphics set, not the greek
	 * letters the 37 has.
	 */
			put(enter_reverse_mode);
			break;
		case SUPERSC:
			/*
			 * This only works on a few terminals.
			 * It should be fixed.
			 */
			put(enter_underline_mode);
			put(enter_dim_mode);
			break;
		case SUBSC:
			put(enter_dim_mode);
			break;
		case UNDERL:
			put(enter_underline_mode);
			break;
		case BOLD:
			put(enter_bold_mode);
			break;
		default:
			/*
			 * We should have some provision here for multiple modes
			 * on at once.  This will have to come later.
			 */
			put(enter_standout_mode);
			break;
		}
	}
	curmode = newmode;
}
示例#2
0
static void
flushln(void)
{
	register int lastmode;
	register int i;
	int hadmodes = 0;

	lastmode = NORMAL;
	for (i=0; i<maxcol; i++) {
		obaccs(i);
		if (obuf[i].c_mode != lastmode) {
			hadmodes++;
			setmod(obuf[i].c_mode);
			lastmode = obuf[i].c_mode;
		}
		if (obuf[i].c_char == '\0') {
			if (upln) {
				put(cursor_right);
			} else
				outc(' ');
		} else
			outc(obuf[i].c_char);
		while (i < maxcol-1 && obuf[i+1].c_mode & FILLER)
			i++;
	}
	if (lastmode != NORMAL) {
		setmod(0);
	}
	if (must_overstrike && hadmodes)
		overstrike();
	putchar('\n');
	if (iflag && hadmodes)
		iattr();
	fflush(stdout);
	if (upln)
		upln--;
	initbuf();
}
示例#3
0
static void
set(void)
{
	int	i, gotcha, not, sspeed = 0;
	speed_t	ispeed0, ospeed0, ispeed1, ospeed1;
	const char	*ap;
	struct termios	tc;

	ispeed0 = ispeed1 = cfgetispeed(&ts);
	ospeed0 = ospeed1 = cfgetospeed(&ts);
	while (*args) {
		for (i = 0; speeds[i].s_str; i++)
			if (strcmp(speeds[i].s_str, *args) == 0) {
				ispeed1 = ospeed1 = speeds[i].s_val;
				sspeed |= 3;
				goto next;
			}
		gotcha = 0;
		if (**args == '-') {
			not = 1;
			ap = &args[0][1];
		} else {
			not = 0;
			ap = *args;
		}
		for (i = 0; modes[i].m_name; i++) {
			if (modes[i].m_type == M_SEPAR || modes[i].m_flg&0100)
				continue;
			if (strcmp(modes[i].m_name, ap) == 0) {
				gotcha++;
				switch (modes[i].m_type) {
				case M_IFLAG:
					setmod(&ts.c_iflag, modes[i], not);
					break;
				case M_OFLAG:
					setmod(&ts.c_oflag, modes[i], not);
					break;
				case M_CFLAG:
				case M_PCFLAG:
					setmod(&ts.c_cflag, modes[i], not);
					break;
				case M_LFLAG:
					setmod(&ts.c_lflag, modes[i], not);
					break;
				case M_CC:
					if (not)
						inval();
					setchr(ts.c_cc, modes[i]);
					break;
				case M_FUNCT:
					modes[i].m_func(not);
					break;
				}
			}
		}
		if (gotcha)
			goto next;
		if (strcmp(*args, "ispeed") == 0) {
			if (*++args == NULL)
				break;
			if (atol(*args) == 0) {
				ispeed1 = ospeed1;
				sspeed |= 1;
				goto next;
			} else for (i = 0; speeds[i].s_str; i++)
				if (strcmp(speeds[i].s_str, *args) == 0) {
					ispeed1 = speeds[i].s_val;
					sspeed |= 1;
					goto next;
				}
			inval();
		}
		if (strcmp(*args, "ospeed") == 0) {
			if (*++args == NULL)
				break;
			for (i = 0; speeds[i].s_str; i++)
				if (strcmp(speeds[i].s_str, *args) == 0) {
					ospeed1 = speeds[i].s_val;
					sspeed |= 2;
					goto next;
				}
			inval();
		}
		gset();
	next:	args++;
	}
	if (sspeed) {
		if (sspeed == 3 && ispeed1 != ospeed1 && ospeed1 != B0) {
			tc = ts;
			cfsetispeed(&tc, ispeed1);
			if (cfgetospeed(&tc) == cfgetospeed(&ts)) {
				tc = ts;
				cfsetospeed(&tc, ospeed1);
				if (cfgetispeed(&tc) == cfgetispeed(&ts)) {
					cfsetispeed(&ts, ispeed1);
					cfsetospeed(&ts, ospeed1);
				}
			}
		} else {
			if (ispeed0 != ispeed1)
				cfsetispeed(&ts, ispeed1);
			if (ospeed0 != ospeed1)
				cfsetospeed(&ts, ospeed1);
		}
	}
}
示例#4
0
文件: event_device.cpp 项目: mhx/aird
void event_device::handle_input_event(const boost::system::error_code& e, size_t /*bytes_read*/)
{
   if (e)
   {
      if (m_stopped && e == boost::asio::error::operation_aborted)
      {
         LINFO(m_log, "stopped");
      }
      else
      {
         LERROR(m_log, "async read failed: " << e.message());
      }

      return;
   }

#ifndef NDEBUG
   if (m_log(log_level::DEBUG))
   {
      debug_input_event();
   }
#endif

   switch (m_iev.type)
   {
      case EV_KEY:
         {
            event_code::type code = event_code::KEYBOARD_ACTIVITY;

            switch (m_iev.code)
            {
               case KEY_LEFTCTRL:
                  setmod(M_CTRL, m_iev.value > 0);
                  break;

               case KEY_LEFTSHIFT:
                  setmod(M_SHIFT, m_iev.value > 0);
                  break;

               case KEY_LEFTALT:
                  setmod(M_ALT, m_iev.value > 0);
                  break;

               case KEY_LEFTMETA:
                  setmod(M_META, m_iev.value > 0);
                  break;

               case KEY_BRIGHTNESSUP:
                  code = m_mod == M_CTRL ? event_code::DISPLAY_BRIGHTNESS_UP_SLOW : event_code::DISPLAY_BRIGHTNESS_UP;
                  break;

               case KEY_BRIGHTNESSDOWN:
                  code = m_mod == M_CTRL ? event_code::DISPLAY_BRIGHTNESS_DOWN_SLOW : event_code::DISPLAY_BRIGHTNESS_DOWN;
                  break;

               case KEY_KBDILLUMUP:
                  code = m_mod == M_CTRL ? event_code::KEYBOARD_BRIGHTNESS_UP_SLOW : event_code::KEYBOARD_BRIGHTNESS_UP;
                  break;

               case KEY_KBDILLUMDOWN:
                  code = m_mod == M_CTRL ? event_code::KEYBOARD_BRIGHTNESS_DOWN_SLOW : event_code::KEYBOARD_BRIGHTNESS_DOWN;
                  break;
            }

            m_handler->handle_event(code);
         }

      case EV_SW:
         switch (m_iev.code)
         {
            case SW_LID:
               m_handler->handle_event(m_iev.value > 0 ? event_code::LID_CLOSED : event_code::LID_OPENED);
               break;
         }

      default:
         break;
   }

   read_next_event();
}