Skip to content

Standardize how we show entity paths to the user #4338

@emilk

Description

@emilk

Problem

Example entity paths, as currently shown with our Display implementation:

  • world/points
  • images/"string"/segmentation
  • images/"My Image.jpeg"/segmentation
  • images/"Random text with newlines \n and quotes \"!"/segmentation

As you see, newlines, quotes etc are already escaped in each individual string, so the formatted entity-path will not contain weird newlines etc.

Our Debug implementation for EntityPath is broken, and escapes newlines and backslashes again, which is just …bad, and should be fixed.

String in paths

Note that there is a difference between names (world, points, images, segmentation) and strings (`"string", "My Image.jpeg", "Random text with newlines \n and quotes "!"). Names are kind to struct-fields, while strings are kin to table keys.

Maybe we shouldn't have this distinction, and instead do what most operating system do with paths: escape slashes and spaces (in addition to newlines etc) in embedded string, i.e.: images/My\ Image.jpeg/segmentation.

How to embed a path in a bigger string

So how do we show an entity path to the user when embedded in a larger string? In GUI:s we could use a separate background color or font, but that doesn't work everywhere (e.g. console logging), so I prefer a solution that is ASCII-based.

Using just Display seems like a bad idea:

  • eprintln!("There is a problem with {entity}") -> There is a problem with humanity

Double-quotes will clash with existing quotes in the string:

  • eprintln!("There is a problem with \"{entity}\"") -> There is a problem with "certain/" bugs and "/issues"

Single-quotes seems better:

  • eprintln!("There is a problem with '{entity}'") -> There is a problem with 'certain/" bugs and "/issues'

Enforcement

Let's assume for a second we opt to select all entity paths in single quotes - how do we enforce it?

We can change Display to add the 'quotes' around the entity-path, and then always use Display (i.e. {}) to display the strings. This is after all the purpose of Display. In the long-run we can add a lint against using Debug-formatting for anything user-facing, but in the short term we can change Debug to act exactly like Display. That way we can't go wrong, as long as we don't add extra explicit quotes (\"{}\"), which we already have a lint against in lint.py`.

There are cases though when entity-paths are standing alone in the UI (streams panel, selection panel) - do we really want to add single-quotes to those places too?

Related issues

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions