• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisionfcadfa98a231e8e695a78934aa02e8e124e2b865 (tree)
Time2018-07-23 03:50:34
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

Load JOY_HOME/definitions.txt

You still can't edit other text files from within the UI, but at least
now you have a place to persist your own definitions over restarts.

I thought about having a [definitions] section in the config INI file,
but for some reason I prefer a separate definitions.txt file. I dunno.
Might change it in future.

Change Summary

Incremental Difference

diff -r 99fec6433bb1 -r fcadfa98a231 joy/gui/main.py
--- a/joy/gui/main.py Sun Jul 22 10:14:45 2018 -0700
+++ b/joy/gui/main.py Sun Jul 22 11:50:34 2018 -0700
@@ -29,7 +29,7 @@
2929
3030 from joy.gui.textwidget import TextViewerWidget, tk, get_font
3131 from joy.gui.world import StackDisplayWorld
32-from joy.library import initialize
32+from joy.library import initialize, DefinitionWrapper
3333 from joy.utils.stack import stack_to_string
3434
3535
@@ -48,7 +48,6 @@
4848 os.path.commonprefix((repo.controldir(), path))
4949 )
5050
51-
5251 def commands():
5352 # pylint: disable=unused-variable
5453
@@ -112,6 +111,7 @@
112111 LOG_FN = os.path.join(JOY_HOME, 'log.txt')
113112 D = initialize()
114113 D.update(commands())
114+DefinitionWrapper.load_definitions(os.path.join(JOY_HOME, 'definitions.txt'), D)
115115 world = StackDisplayWorld(repo, STACK_FN, REL_STACK_FN, dictionary=D)
116116 defaults = dict(width=80, height=25)
117117 t = TextViewerWidget(world, **defaults)
diff -r 99fec6433bb1 -r fcadfa98a231 joy/library.py
--- a/joy/library.py Sun Jul 22 10:14:45 2018 -0700
+++ b/joy/library.py Sun Jul 22 11:50:34 2018 -0700
@@ -380,6 +380,13 @@
380380 _log.info('Adding definition %s := %s', F.name, expression_to_string(F.body))
381381 dictionary[F.name] = F
382382
383+ @classmethod
384+ def load_definitions(class_, filename, dictionary):
385+ with open(filename) as f:
386+ lines = [line for line in f if '==' in line]
387+ for line in lines:
388+ class_.add_def(line, dictionary)
389+
383390
384391 def _text_to_defs(text):
385392 return (line.strip() for line in text.splitlines() if '==' in line)
Show on old repository browser