Server side implementation for interactive entry edits
This commit is contained in:
60
sia/entry/read_entry.py
Normal file
60
sia/entry/read_entry.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from . import Entry
|
||||
from ..io_buffer import IOBuffer
|
||||
|
||||
class ReadEntry(Entry):
|
||||
"""
|
||||
Entry type for reading content from standard input.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str,
|
||||
io_buffer: IOBuffer,
|
||||
):
|
||||
"""
|
||||
Initialize a new read entry.
|
||||
|
||||
Args:
|
||||
id: Unique identifier for this entry
|
||||
io_buffer: Buffer to use for IO operations
|
||||
"""
|
||||
super().__init__(id)
|
||||
self.content: str = "",
|
||||
self.read = False
|
||||
self._io_buffer = io_buffer
|
||||
|
||||
def update(self) -> None:
|
||||
"""
|
||||
Read from stdin if not already read.
|
||||
Uses the provided IO buffer for the actual read operation.
|
||||
"""
|
||||
if not self.read:
|
||||
self.content = self._io_buffer.read()
|
||||
self.read = True
|
||||
self.notify_change()
|
||||
|
||||
def generate_context(self) -> ET.Element:
|
||||
"""
|
||||
Generate an XML Element representing this read entry.
|
||||
|
||||
Returns:
|
||||
ET.Element: XML element containing the entry's data
|
||||
"""
|
||||
element = ET.Element("read_stdin", {"id": self._id})
|
||||
if self.read:
|
||||
element.text = self.content
|
||||
|
||||
return element
|
||||
|
||||
def serialize(self):
|
||||
"""
|
||||
Collect all public attributes of the entry into a dictionary.
|
||||
"""
|
||||
return {
|
||||
"type": "read_stdin",
|
||||
"id": self._id,
|
||||
"content": self.content,
|
||||
"read": self.read,
|
||||
}
|
||||
Reference in New Issue
Block a user