Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:00:39+00:00 2026-05-24T03:00:39+00:00

This is my first post to stack overflow. I’ve been lurking this site for

  • 0

This is my first post to stack overflow. I’ve been lurking this site for information for years, and it’s always helpful, so I thought that I would post my first question.

I’ve been searching for some similar examples, but can’t seem to find anything.

Ultimately, I’m trying to write a simple text ui for finding false positives and false negatives in a text extraction program. The false positive module is a simple yes/no selection, and displaying colored text and using getch() is easy enough. The False negative portion however, is a becoming difficult.

So this is what I want to do:

  1. Display a string onto the screen (forget scrolling for now…. ugh) It will only be a string with no newlines.
  2. The user sees the text, and pushes ‘h’ to enter highlight mode.
  3. The user can then control the cursor to move it over a portion of the text (still displayed), and select ‘v’ to begin highlighting (I trying to make this as close to vi as I can)
  4. The user then uses control keys (arrows, hjkl) to move the cursor from a starting point to and end point, highlighting the text on the way. This highlighted portion should be a word which is a false negative
  5. The user presses some key (‘y’ probably), and the selected text is colored, or stays highlighted, and the highlighted text is save to some variable that I’ll handle later.
  6. The user exits highlight mode and proceeds.

Any ideas to even START? I’m trying simple things like keeping text on the screen and moving the cursor around, but to no avail.

I’m aware of the curses.textpad.TextBox() module, but it performs editing like insertion and deletion, which I don’t want to do. Perhaps there is a way to disable it.

I have other questions, but I’ll keep this specific for now.

Thanks!!

Neal

Edit: To be more specific, I’m not looking for help writing the whole program, just help moving the cursor over displayed text, highlighting it, and selecting it and saVing it in a variable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:00:39+00:00Added an answer on May 24, 2026 at 3:00 am

    I would like to update this question in case anybody else is searching the web for this and stumbles upon this question.

    Okay, so the answer was actually quite simple and required reading all the functions listed on the python curses documentation.

    What I did was make a 3 state machine: State 1: Normal mode (displays text only), State 2: highlight mode, allow the cursor to move around the window, and State 3: highlighter mode, which gives only limited movement from left to right over texts and highlights the text as it’s moving.

    To accomplish this task, it just takes some basic curses function calls.

    I made separate windows, but I’ll just assume a single window for explaination.

    Do display text in the window, stick with the:

    window.addstr()
    window.refresh()
    

    For moving the cursor around:

    #get current cursor position
    curr_y, curr_x = window.getyx()
    
    # depending on direction, update the cursor with
    next_y, next_x = get_next_direction()
    
    # place cursor in new position
    window.move(next_y, next_x)
    
    window.refresh()
    

    Once the cursor is over the starting point for highlighting, press ‘v’ enter the highlighter state, and limit the movement of the cursor, change the attribute of the selected text:

    # get current cursor position
    curr_y, curr_x = window.getyx()
    
    # save position for later use
    start_y = curr_y; start_x = curr_x
    
    # loop until 'v' is pressed again
    while highlight_state:
        # change the attribute of the current character, for 1 character only, to reverse
        window.chgat(curr_y,curr_x, 1, curses.A_REVERSE)
        curr_y, curr_x = get_next_direction()
    
    # save end state, this is buggy obviously, but you get the point
    end_y = curr_y; end_x = curr_X
    

    Now extract that information from start to end

    # get integer representation of char at positiong
    
    outstr = ''
    #from start to end
    char_as_int = windows.inch(y,x)
    char = char_as_int & 0000FF
    attr = char_as_int & FFFF00 #not useful here, but maybe later
    
    outstr += char
    

    That’s it! I also tried another way to save the highlighted material which was basically transformat the x,y coordinates to the index of the string that was being display, but that let to issue in string representation (newlines, tabs, and so on), plus was just harder to do.

    If anyone has comments of a more efficient/ cleaner method, please respond!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post to stack overflow,... :) I like this site a
This is my first post on Stack Overflow and I'm just wondering on the
This is my first post on Stack Overflow. I am trying to build a
Ahoy Stack Overflow! This be mai first post... I'm attempting to identify users with
This is my first post on Stack Overflow so please exuse (and feel free
this is my first post on stack overflow! I'm new to Java and I've
Woot, first Stack Overflow post! I've been asked to work on a desktop application
Well, this is my first post here and really enjoying the site. I have
This is my first post, so please be gentle. I've been playing around with
first post here on stack overflow, hoping to get some advice on how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.