Exemplo n.º 1
0
    def load(self):
        if 'all' in self.force_start:
            self.primer_arg += 'S'
            self.force_start = []
        if 'all' in self.scroll:
            self._scrollfile = None
        out('session "%s" loading "%s"' % (self.pid, os.path.join(self.basedir,
            self.savedir)))

        #check if the saved session exists and get the biggest saved window number and a number of saved windows

        maxnewwindow = 0
        newwindows = 0
        try:
            winlist = list(glob.glob(os.path.join(self.basedir, self.savedir,
                           'win_*')))
            newwindows = len(winlist)
            out('%d new windows' % newwindows)
        except Exception:
            sys.stderr.write('Unable to open winlist.\n')
            return 1

        # keep original numbering, move existing windows

        self.homewindow = self.number()

        if self.exact:
            maxnewwindow = -1
            for w in winlist:
                try:
                    w = int(w.rsplit("_", 1)[1])
                    if w > maxnewwindow:
                        maxnewwindow = w
                except:
                    pass

            out('Biggest new window number: %d' % maxnewwindow)
            if self.enable_layout:
                self.__remove_all_layouts()
            self.__move_all_windows(maxnewwindow + 1, self.group_other,
                                    False)

        out("\nLoading windows:")
        self.__load_screen()

        if self.enable_layout:
            out("\nLoading layouts:")
            try:
                self.__load_layouts()
            except:
                sys.stderr.write('Layouts loading failed!\n')
                # raise

        self.__restore_mru()
        sc.cleanup()

        return 0
Exemplo n.º 2
0
    def load(self):
        if "all" in self.force_start:
            self.primer_arg += "S"
            self.force_start = []
        if "all" in self.scroll:
            self._scrollfile = None
        out('session "%s" loading "%s"' % (self.pid, os.path.join(self.basedir, self.savedir)))

        # check if the saved session exists and get the biggest saved window number and a number of saved windows

        maxnewwindow = 0
        newwindows = 0
        try:
            winlist = list(glob.glob(os.path.join(self.basedir, self.savedir, "win_*")))
            newwindows = len(winlist)
            out("%d new windows" % newwindows)
        except Exception:
            sys.stderr.write("Unable to open winlist.\n")
            return 1

        # keep original numbering, move existing windows

        self.homewindow = self.number()

        if self.exact:
            maxnewwindow = -1
            for w in winlist:
                try:
                    w = int(w.rsplit("_", 1)[1])
                    if w > maxnewwindow:
                        maxnewwindow = w
                except:
                    pass

            out("Biggest new window number: %d" % maxnewwindow)
            if self.enable_layout:
                self.__remove_all_layouts()
            self.__move_all_windows(maxnewwindow + 1, self.group_other, False)

        out("\nLoading windows:")
        self.__load_screen()

        if self.enable_layout:
            out("\nLoading layouts:")
            try:
                self.__load_layouts()
            except:
                sys.stderr.write("Layouts loading failed!\n")
                # raise

        self.__restore_mru()
        sc.cleanup()

        return 0
Exemplo n.º 3
0
def cleanup():
    cmd = ''
    f = open(sourcefile, 'w')
    for (i, w) in enumerate(win_history):
        if w == "-1":
            w = "-"
        f.write("""select %s
at \"%s\#\" kill
focus
""" % (w, wins[i]))
    f.flush()
    f.close()
    scs.source(sourcefile)
    scs.focusminsize(focusminsize)
    sc.cleanup()
    remove(sourcefile)
Exemplo n.º 4
0
def prepare_windows(scs):
    global focusminsize
    regions = None
    regions = sc.get_regions(sc.dumpscreen_layout(scs.pid))
    sc.cleanup()
    focusminsize = "%s %s" % (regions.focusminsize_x, regions.focusminsize_x)
    regions_c = len(regions.regions)
    focus_offset = regions.focus_offset
    scs.focusminsize('0 0')
    this_win_history = []
    cmd = ''
    f = open(sourcefile, 'w')
    for i in range(0, regions_c):
        f.write("""screen -t scs-regions-helper %s %s %s %d
focus
""" %
                (subprogram, subprogram_args, inputfile, i))
    f.flush()
    f.close
    scs.source(sourcefile, "screen-session regions")
    remove(sourcefile)

    regions_n = []
    regions_n = sc.get_regions(sc.dumpscreen_layout(scs.pid))
    sc.cleanup()

    for r in (regions.regions)[focus_offset:]:
        this_win_history.append(r[0])
    for r in (regions.regions)[:focus_offset]:
        this_win_history.append(r[0])

    new_windows = []
    for r in (regions_n.regions)[focus_offset:]:
        new_windows.append(r[0])
    for r in (regions_n.regions)[:focus_offset]:
        new_windows.append(r[0])

    return (this_win_history, new_windows, regions_c)
Exemplo n.º 5
0
        if ret:
            sys.stderr.write('session saving failed\n')
            scs.Xecho("screen-session saving FAILED")
        else:
            out('compressing...')
            scs.Xecho("screen-session compressing...")
            removeit(os.path.join(home, projectsdir, savedir_real))
            removeit(os.path.join(util.tmpdir, savedir_real))
            archiveme(util.tmpdir, home, projectsdir, savedir_real, util.archiveend,
                      savedir_real + '__tmp/*')
            removeit(os.path.join(home, projectsdir, savedir_tmp))
            removeit(os.path.join(util.tmpdir, savedir_tmp))
            scs.savedir = savedir_real
            savedir = savedir_real
            sc.cleanup()
            out('session "%s"' % scs.pid)
            out('saved as "%s"' % scs.savedir)
            scs.Xecho("screen-session finished saving as \"%s\"" %
                      savedir)
    elif mode == 2:  #mode load

        #cleanup old temporary files and directories

        cleantmp(util.tmpdir, home, projectsdir, util.archiveend, scs.blacklistfile,
                 500)

        # unpack and load

        try:
            unpackme(home, projectsdir, savedir, util.archiveend, util.tmpdir)
Exemplo n.º 6
0
def nest_layout(session, src_layuot, dst_layout):
    src_dumpfile = os.path.join(tmpdir_source, 'nest_layout-dump-%d' % os.getpid())

    if not os.path.exists(tmpdir_source):
        os.makedirs(tmpdir_source)

    scs = ScreenSaver(session)

    print('layouts src: %s dst: %s' % (src_layout, dst_layout))

    regions_file_dst = regions_file = sc.dumpscreen_layout(scs.pid)
    regions_dst = sc.get_regions(regions_file)

    dst_focusminsize = "%s %s" % (regions_dst.focusminsize_x, regions_dst.focusminsize_y)
    dst_rsize = (int(regions_dst.regions[regions_dst.focus_offset][1]),
                int(regions_dst.regions[regions_dst.focus_offset][2]))
    dst_term_size = (int(regions_dst.term_size_x),
                    int(regions_dst.term_size_y))
    scs.layout('select %s' % src_layout, False)

    scs.layout('dump %s' % src_dumpfile, False)

    regions_file_src = sc.dumpscreen_layout(scs.pid)
    regions_src = sc.get_regions(regions_file_src)

    src_term_size = (int(regions_src.term_size_x), int(regions_src.term_size_y))

    print ('dst_rsize: %s' % str(dst_rsize))
    print ('src_term_size: %s' % str(src_term_size))

    scs.layout('select %s' % dst_layout, False)
    
    regions_new = sc.Regions()
    regions_new.focus_offset =  regions_dst.focus_offset + regions_src.focus_offset
    regions_new.term_size_x = regions_dst.term_size_x
    regions_new.term_size_y = regions_dst.term_size_y
    regions_new.focusminsize_x = regions_dst.focusminsize_x
    regions_new.focusminsize_y = regions_dst.focusminsize_y
    regions_new.regions = regions_dst.regions[:regions_dst.focus_offset]

    for (window, sizex, sizey) in regions_src.regions:
        print('SRC REGION' + str((window,sizex,sizey)))
        x = (int(sizex) * dst_rsize[0]) / src_term_size[0]
        y = (int(sizey) * dst_rsize[1]) / src_term_size[1]
        print( '%s * %d / %d = %d' % (sizex, dst_rsize[0], src_term_size[0], x))
        print( '%s * %d / %d = %d' % (sizey, dst_rsize[1], src_term_size[0], y))
        regions_new.regions.append((window, str(x), str(y)))

    regions_new.regions = regions_new.regions + regions_dst.regions[regions_dst.focus_offset+1:]
    
    print('destination regions: '+ str(regions_dst.regions))
    print('source regions: ' + str(regions_src.regions))
    print('new regions: ' + str(regions_new.regions))

    sc.layout_begin(session)
    sc.layout_load_dump(open(src_dumpfile, 'r'))
    sc.layout_load_regions(regions_new, None, dst_term_size[0], dst_term_size[1])
    sc.layout_end()

    remove(src_dumpfile)
    remove(regions_file_dst)
    remove(regions_file_src)
    sc.cleanup()
Exemplo n.º 7
0
def cleanup():
    sc.cleanup()
Exemplo n.º 8
0
def cleanup():
    sc.cleanup()
Exemplo n.º 9
0
def run(session, requirecleanup_win, requirecleanup_lay, curwin, curlay,
        height, select_other = False):
    global lock_and_com_file, mru_file
    lltmpdir = os.path.join(tmpdir, '___layoutlist')
    try:
        os.makedirs(lltmpdir)
    except:
        pass

    signal.signal(signal.SIGINT, handler)
    session = session.split('.', 1)[0]

    ret = 0
    ss = ScreenSaver(session)
    wnum = os.getenv('WINDOW')
    if requirecleanup_lay:
        lnum = ss.get_layout_number()[0]
    else:
        lnum = None

    mru_file = os.path.join(lltmpdir, '%s_MRU' % session)
    if select_other:
        mru_layouts = pickle.load(open(mru_file, 'r'))
        num, title = mru_layouts[1]
        tmp = mru_layouts[0]
        mru_layouts[0] = mru_layouts[1]
        mru_layouts[1] = tmp
        ss.command_at(False, 'eval "layout select %s" "layout title"' %
                      num)
        pickle.dump(mru_layouts, open(mru_file, 'w'))
        return ret
    if NO_END:
        lock_and_com_file = os.path.join(lltmpdir, '%s' %
                session)
        f = open(lock_and_com_file, 'w')
        f.write(str(os.getpid()) + '\n')
        if requirecleanup_win and not requirecleanup_lay:
            f.write(wnum + '\n')
        else:
            f.write('-1\n')
        if requirecleanup_lay:
            f.write(lnum + '\n')
        else:
            f.write('-1\n')
        f.close()

    try:
        try:
            layinfo = list(sc.gen_layout_info(ss, sc.dumpscreen_layout_info(ss)))
        finally:
            sc.cleanup()
    except:
        sys.stderr.write('Layouts dumping error.\n')
        return 1
    screen = curses.initscr()
    (laytable, pos_start) = create_table(ss, screen, curlay, layinfo,
            lnum, height)
    try:
        curses.start_color()
    except:
        curses.endwin()
        sys.stderr.write('start_color() failed!\n')
        return 1

    curses.noecho()

    #screen.notimeout(1)

    try:
        choice = menu_table(
            ss,
            screen,
            lnum,
            curwin,
            curlay,
            layinfo,
            laytable,
            pos_start[0],
            pos_start[1],
            height,
            )
        if requirecleanup_lay and choice == lnum:
            choice = curlay
    except Exception:
        import traceback
        traceback.print_exc(file=sys.stderr)
        choice = curlay
        ret = 1
    curses.endwin()
    if NO_END:
        from util import remove
        remove(lock_and_com_file)
    if requirecleanup_lay:
        ss.command_at(False,
                      'eval "layout select %s" "layout remove %s" "at \"%s\#\" kill" "layout title"' %
                      (choice, lnum, wnum))
    elif requirecleanup_win:
        ss.command_at(False,
                      'eval "select %s" "layout select %s" "at \"%s\#\" kill" "layout title"' %
                      (curwin, choice, wnum))
    else:
        ss.command_at(False, 'eval "layout select %s" "layout title"' %
                      choice)
    return ret
Exemplo n.º 10
0
def menu_table(
    ss,
    screen,
    tmplay,
    curwin,
    curlay,
    layinfo,
    laytable,
    pos_x,
    pos_y,
    height,
    ):
    global MAXTITLELEN
    global mru_file
    (y, x) = screen.getmaxyx()

    # default background colors

    try:
        curses.use_default_colors()
    except:
        pass

    ## custom background
    #curses.init_pair(1,curses.COLOR_WHITE, curses.COLOR_BLACK)
    #screen.bkgd(' ',curses.color_pair(1))

    # ?universal? color scheme

    curses.init_pair(2, -1, curses.COLOR_YELLOW)
    curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLUE)
    curses.init_pair(4, -1, curses.COLOR_GREEN)
    curses.init_pair(5, -1, -1)
    curses.init_pair(6, curses.COLOR_RED, -1)
    curses.init_pair(7, curses.COLOR_RED, curses.COLOR_YELLOW)
    curses.init_pair(8, curses.COLOR_RED, curses.COLOR_BLUE)
    curses.init_pair(9, curses.COLOR_RED, curses.COLOR_GREEN)

    c_h = curses.color_pair(2) | curses.A_BOLD
    c_n = curses.A_NORMAL
    c_curlay_n = curses.color_pair(3) | curses.A_BOLD
    c_find = curses.color_pair(4)
    c_error = curses.color_pair(5) | curses.A_BOLD
    c_project = curses.color_pair(6) | curses.A_BOLD
    c_h_project = curses.color_pair(7)
    c_curlay_project = curses.color_pair(8) | curses.A_BOLD
    c_find_project = curses.color_pair(9)
    screen.keypad(1)
    x = None
    other_num = last_sel_num = sel_num_before_search = sel_num = curlay
    row_len = None
    col_len = None
    search_num = None
    search_title = ""
    n_search_title = ""
    searching_num = False
    searching_title = False
    b_force_sel_num = False
    status_len = 0
    errormsg = ""
    findNext = 0
    current_view = 'n'
    try:
        mru_layouts = pickle.load(open(mru_file, 'r'))
    except:
        mru_layouts = []
    view_layouts = []
    pos_x_c = pos_y_c = layinfo_c = laytable_c = None

    def mru_add(layout_num):
        layout_title = ""
        index = None
        for (i, lay) in enumerate(mru_layouts):
            (num, title) = lay
            if num == layout_num:
                index = i
                break
        if index != None:
            mru_layouts.pop(index)
        for lay in layinfo:
            try:
                num = lay[0]
                title = lay[1]
            except:
                title = ""
            if num == layout_num:
                layout_title = title
                break
        mru_layouts.insert(0, (layout_num, layout_title))
        pickle.dump(mru_layouts, open(mru_file, 'w'))

    mru_add(curlay)
    while True:
        view_layouts = []
        keyboard_int = False
        if findNext and n_search_title:
            layinfo_pos = 0
            for (k, e) in enumerate(layinfo):
                if e[0] == sel_num:
                    layinfo_pos = k
            layinfo_tmp = layinfo[layinfo_pos + 1:] + layinfo[:layinfo_pos]
            if findNext == -1:
                layinfo_tmp.reverse()
            for (i, entry) in enumerate(layinfo_tmp):
                try:
                    num = entry[0]
                    title = entry[1]
                except:
                    title = ""
                try:
                    tfi = title.lower().strip().index(n_search_title.lower())
                    sel_num = num
                    break
                except:
                    continue
        elif searching_num:
            bfound = False
            if not search_num:
                sn = sel_num_before_search
                searching_num = False
            else:
                sn = search_num
            for (i, row) in enumerate(laytable):
                for (j, cell) in enumerate(row):
                    (num, title) = cell
                    if sn:
                        if sn == num:
                            pos_x = j
                            pos_y = i
                            bfound = True
                            break
                    if bfound:
                        break

        project_title = None
        bfound = False
        for (i, row) in enumerate(laytable):
            for (j, cell) in enumerate(row):
                (num, title) = cell
                if sel_num == last_sel_num and j == pos_x and i == pos_y and \
                    not b_force_sel_num:
                    sel_num = num
                    last_sel_num = sel_num
                    row_len = len(row) - 1
                    project_title = title.lower()
                    bfound = True
                    break
                elif (b_force_sel_num or not sel_num == last_sel_num) and \
                    sel_num == num:
                    b_force_sel_num = False
                    pos_x = j
                    pos_y = i
                    last_sel_num = sel_num
                    row_len = len(row) - 1
                    project_title = title.lower()
                    bfound = True
                    break
            if bfound:
                break
        if sel_num != curlay:
            other_num = sel_num
        bSearchResults = False
        for (i, row) in enumerate(laytable):
            for (j, cell) in enumerate(row):
                (num, title) = cell
                bsel = False
                c_f = c_find
                if sel_num == num:
                    color = c_h
                    c_p = c_h_project
                    bsel = True
                elif num == curlay:
                    color = c_curlay_n
                    c_p = c_curlay_project
                else:
                    color = c_n
                    c_p = c_project
                try:
                    screen.addstr(i, j * (MAXTITLELEN + 5), " %-4s%s" %
                                  (num, title), color)
                    tl = title.lower()
                    if AUTOSEARCH_MIN_MATCH > 0:
                        pi = 0

                        for (k, l) in enumerate(tl):
                            try:
                                if l == project_title[k]:
                                    pi += 1
                                else:
                                    break
                            except:
                                break
                        if pi >= AUTOSEARCH_MIN_MATCH:
                            if bsel:
                                screen.addstr(i, j*(MAXTITLELEN+5), " %-4s"%(num), c_p)
                            else:
                                screen.addstr(i, j*(MAXTITLELEN+5)+5, "%s"%(title[0:pi]), c_p)
                            if not bsel:
                                c_f = c_find_project

                    if findNext:
                        s = n_search_title
                    else:
                        s = search_title
                    tfi = tl.strip().index(s.lower())
                    if not bSearchResults:
                        bSearchResults = True
                        view_layouts = []
                    screen.addstr(i, j * (MAXTITLELEN + 5) + 5 + tfi,
                                  "%s" % title[tfi:tfi + len(s)], c_f)
                except:
                    pass

        if findNext:
            findNext = 0
        if not searching_num:
            search_num = None
        if not searching_title:
            search_title = None
        try:
            screen.addstr(y - 1, 0, "> %-*s" % (status_len, ""), c_n)
            if searching_title or searching_num:
                if searching_title:
                    prompt = '> Search: '
                else:
                    prompt = '> Number: '
                if search_title:
                    search = search_title
                elif search_num:
                    search = search_num
                else:
                    search = ""
                s = "%s%s" % (prompt, search)
                status_len = len(s)
                screen.addstr(y - 1, 0, s, curses.A_BOLD)
            else:
                if errormsg:
                    s = "%s" % errormsg
                    screen.addstr(y - 1, 2, s, c_error | curses.A_BOLD)
                else:
                    s = 'Press \'?\' to view help'
                    screen.addstr(y - 1, 2, s, c_n)
                status_len = len(s)
                errormsg = ""
        except:
            pass

        screen.refresh()
        x = screen.getch()

        # layout list refresh ^C ^L ^R

        if x in (-1, 12, 18) or x in (ord('r'), ord('R')) and not searching_title and \
            not searching_num:
            if laytable_c:
                current_view = 'n'
                pos_x = pos_x_c
                pos_y = pos_y_c
                pos_x_c = pos_y_c = layinfo_c = laytable_c = None
            (y, x) = screen.getmaxyx()
            searching_title = False
            searching_num = False
            try:
                try:
                    try:
                        if NO_END:
                            f = open(lock_and_com_file, 'r')
                            from string import strip as str_strip

                            #pid,cwin,clay,MAXTITLELEN,height = map( str_strip,f.readlines() )

                            nd = map(str_strip, f.readlines())
                            curwin = nd[3]
                            sel_num = curlay = nd[4]
                            MAXTITLELEN = int(nd[5])
                            height = int(nd[6])
                            f.close()
                            screen.erase()
                            mru_add(curlay)
                    except:
                        pass
                    layinfo = list(sc.gen_layout_info(ss, sc.dumpscreen_layout_info(ss)))
                    (laytable, pos_start) = create_table(ss, screen,
                            curlay, layinfo, tmplay, height)
                    errormsg = 'Refreshed'
                finally:
                    sc.cleanup()
            except:
                errormsg = 'Layouts dumping error.'
        elif searching_title and x == ord('\n'):
            searching_title = False
            n_search_title = search_title
            findNext = True
        elif x == 27:

                      # Escape key

            searching_num = False
            searching_title = False
            search_num = None
            search_title = None
            errormsg = 'Canceled'
            n_search_title = search_title
        elif x == curses.KEY_BACKSPACE:
            try:
                if len(search_num) == 0:
                    raise Exception
                search_num = search_num[:-1]
            except:
                searching_num = False
                pass
            try:
                if len(search_title) == 0:
                    raise Exception
                search_title = search_title[:-1]
            except:
                searching_title = False
                pass
        elif searching_title:
            if x == curses.KEY_UP:
                search_title = n_search_title
            elif x == curses.KEY_DOWN:
                search_title = ""
            else:
                try:
                    search_title += chr(x)
                except:
                    pass
        elif x in (ord('/'), ord(' ')):
            searching_title = True
            searching_num = False
            search_title = ""
        elif x == ord('\n'):
            if layinfo_c:
                current_view = 'n'
                layinfo = list(layinfo_c)
                laytable = list(laytable_c)
                pos_x = pos_x_c
                pos_y = pos_y_c
                pos_x_c = pos_y_c = layinfo_c = laytable_c = None
            searching_num = False
            if not sel_num:
                curses.flash()
                errormsg = "No layout selected."
            elif sel_num == tmplay:
                curses.flash()
                errormsg = "This IS layout %s." % sel_num
            else:
                if NO_END:
                    mru_add(sel_num)
                    if curwin != '-1':
                        ss.command_at(False,
                                'eval "select %s" "layout select %s" "layout title"' %
                                (curwin, sel_num))
                    else:
                        ss.command_at(False,
                                'eval "layout select %s" "layout title"' %
                                sel_num)
                else:
                    return sel_num
        elif x in (ord('q'), ord('Q')):
            if NO_END and x == ord('q'):
                if layinfo_c:
                    current_view = 'n'
                    layinfo = list(layinfo_c)
                    laytable = list(laytable_c)
                    pos_x = pos_x_c
                    pos_y = pos_y_c
                    pos_x_c = pos_y_c = layinfo_c = laytable_c = None
                mru_add(sel_num)
                ss.command_at(False,
                              'eval "layout select %s" "layout title"' %
                              curlay)
            else:
                return curlay
        elif x in (ord('n'), ord('P')):
            findNext = 1
        elif x in (ord('p'), ord('N')):
            findNext = -1
        elif x in (curses.KEY_HOME, ord('^')):
            pos_x = 0
        elif x in (curses.KEY_END, ord('$')):
            pos_x = len(laytable[pos_y]) - 1
        elif x == curses.KEY_PPAGE:
            pos_y = pos_y - 5 > 0 and pos_y - 5 or 0
        elif x == ord('?'):
            from help import help_layoutlist
            screen.erase()
            for (i, line) in enumerate(help_layoutlist.split('\n')):
                try:
                    screen.addstr(i, 0, " %s" % line, c_n)
                except:
                    pass
            screen.refresh()
            x = screen.getch()
            screen.erase()
        elif x == ord('o'):
            if sel_num != curlay:
                other_num = sel_num
                sel_num = curlay
            else:
                sel_num = other_num
            b_force_sel_num = True
        elif x in (ord('m'), ord('a')):
            screen.erase()
            if not layinfo_c:
                current_view = 'm'
                layinfo_c = list(layinfo)
                laytable_c = list(laytable)
                layinfo = mru_layouts
                pos_x_c = pos_x
                pos_y_c = pos_y
                pos_x = pos_y = 0
                (laytable, pos_start) = create_table_std(ss, screen,
                        curlay, layinfo, tmplay)
                if len(laytable) > 1:
                    pos_y = 1
            else:
                current_view = 'n'
                b_force_sel_num = True
                layinfo = list(layinfo_c)
                laytable = list(laytable_c)
                pos_x = pos_x_c
                pos_y = pos_y_c
                pos_x_c = pos_y_c = layinfo_c = laytable_c = None
        elif x == ord('v'):
            screen.erase()
            if not layinfo_c:
                current_view = 'v'
                layinfo_c = list(layinfo)
                laytable_c = list(laytable)
                pos_x_c = pos_x
                pos_y_c = pos_y
                pos_x = pos_y = 0
                nst = n_search_title.lower()
                for lay in layinfo:
                    try:
                        num = lay[0]
                        title = lay[1]
                    except:
                        title = ""
                    tl = title.lower().strip()
                    if bSearchResults:
                        try:
                            tfi = tl.index(nst)
                            view_layouts.append((num, title))
                        except:
                            pass
                    else:
                        pi = 0
                        for (k, l) in enumerate(tl):
                            try:
                                if l == project_title[k]:
                                    pi += 1
                                else:
                                    break
                            except:
                                break
                        if pi >= AUTOSEARCH_MIN_MATCH:
                            view_layouts.append((num, title))

                (laytable, pos_start) = create_table_std(ss, screen,
                        sel_num, view_layouts, tmplay)
                (pos_x, pos_y) = pos_start
                layinfo = view_layouts
            else:
                current_view = 'n'
                b_force_sel_num = True
                layinfo = list(layinfo_c)
                laytable = list(laytable_c)
                pos_x = pos_x_c
                pos_y = pos_y_c
                pos_x_c = pos_y_c = layinfo_c = laytable_c = None
        elif x in range(ord('0'), ord('9') + 1):
            if not searching_num:
                searching_num = True
                sel_num_before_search = sel_num
            if not search_num:
                search_num = chr(x)
            else:
                try:
                    search_num += chr(x)
                except:
                    pass
        else:
            searching_num = False
            for (i, row) in enumerate(laytable):
                try:
                    a = row[pos_x]
                    col_len = i
                except:
                    break

            #sys.stderr.write("KEY(%d) POS(%d,%d) RLEN(%d) CLEN(%d)\n"%(x,pos_x,pos_y,row_len,col_len))

            if x == curses.KEY_NPAGE:
                pos_y = pos_y + 5 < col_len and pos_y + 5 or col_len
            elif x in (ord('j'), curses.KEY_DOWN):
                if pos_y < col_len:
                    pos_y += 1
                else:
                    pos_y = 0
            elif x in (ord('k'), curses.KEY_UP):
                if pos_y > 0:
                    pos_y += -1
                else:
                    pos_y = col_len
            elif x in (ord('h'), curses.KEY_LEFT):
                if pos_x > 0:
                    pos_x += -1
                else:
                    pos_x = row_len
            elif x in (ord('l'), curses.KEY_RIGHT):
                if pos_x < row_len:
                    pos_x += 1
                else:
                    pos_x = 0
            else:
                try:
                    c = chr(x)
                except:
                    c = 'UNKNOWN'
                errormsg = 'Unsupported keycode: %d \"%s\"' % (x, c)
                curses.flash()