scripts.eww

The Eww client is the recommended frontend for connecting to a listening Eww instance.

Before criticizing this implementation, it’s important to understand why this was done.

I consider readline support a hard requirement.

readline is currently only supported by raw_input(). readline does expose a few calls into the underlying library, but not nearly what we need to implement it ourselves without using raw_input().

There are a few solutions to this problem:

  1. Implement readline-like support ourselves in Python
  2. Call the underlying C library ourselves
  3. Implement proper PTY support on both ends of the connection
  4. Use raw_input()

Option 1 is a lot more work than it seems like. It would certainly be valuable, and an interesting library to create. The scope of work required to do it properly just for this is difficult to justify.

Option 2 would require a compilation step and complicate installation.

Option 3 would be ideal. However, implementing a cross-platform PTY over a socket in Python is difficult, error-prone, and tough to debug. It’s absolutely on the table and would let us add a ton of features, but it’s not happening right off the bat.

Which leaves us with option 4, and results in our current (difficult to test) implementation.

With that in mind, read on.

exception scripts.eww.ConnectionClosed[source]

Bases: exceptions.Exception

Raised when a connection is closed.

__weakref__

list of weak references to the object (if defined)

class scripts.eww.EwwClient(host, port)[source]

Bases: object

Manages all client communication.

__init__(host, port)[source]

Init.

Parameters:
  • host (str) – A host to connect to.
  • port (int) – A port to connect to.
__weakref__

list of weak references to the object (if defined)

clientloop(debug=False, line=None)[source]

Repeatedly loops through display_output and get_input.

Parameters:
  • debug (bool) – Used for testing. If debug is True, clientloop only goes through one iteration.
  • line (str) – If debug is True, this will be passed to get_input. Useful for testing.
Returns:

None

connect()[source]

Connects to an Eww instance.

Returns:None
display_output()[source]

Displays output from the Eww instance.

Returns:None
get_input(line=None)[source]

Collects user input and sends it to the Eww instance.

Parameters:line (str) – If provided, line is considered the input and raw_input is not used.
Returns:None
scripts.eww.main(debug=False, line=None, opt_args=None)[source]

Main function.

Parameters:
  • debug (bool) – Used for testing. If debug is True, clientloop only goes through one iteration.
  • line (str) – If debug is True, this will be passed to get_input. Useful for testing.
  • opt_args (list) – If debug is True, this list is parsed by optparse instead of sys.argv.
Returns:

None