marick

marick

Is there a Hex package similar to Apple's NSAttributedString?

I’d like to be able to attach attributes to ranges within a string. Since I’m writing prototypes/spikes in Elixir for an eventual MacOS app, it’d be nice if the capabilities were similar to NSAttributedString - even better, a process that makes a mutable version of that (equivalent to NSMutableAttributedString). However, anything that saves me the trouble of dealing with all the fiddly cases around maintaining attributes as the underlying string changes is more than fine.

First Post! Switch mode

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

In one sense I’m not sure how to answer this question. The entire framing is that you want a thing that doesn’t look anything like an Elixir string in that it has attributes, and those attributes are mutable. Can you expand on the larger problem you are trying to solve, and elaborate on how this specific data structure helps accomplish a solution to that problem?

Most Liked

marick

marick

Consider a text editor, which manages a mutable string. Ranges of characters can be assigned particular attributes. Conceptually, every character in the string comes with a key/value map named “attributes”. Some keys are predefined, but apps can define their own custom attributes.

You can ask questions like:

  1. What attributes does the 34th Unicode character in the string have?
  2. What’s the largest contiguous Range of characters that all have the same attributes as character 34?
  3. Is the :italic attribute set for character 34?
  4. For what range around character 34 is the :italic attribute set?

I’m writing an app to explore coding in a style inspired by ecological and embodied cognition. Mainly for fun and to keep me off the streets.

Last Post!

marick

marick

In particular: the editing app is conceptualized as (for example) watching a paragraph the way a cat watches a mousehole. More specifically, there’ll be a process focused on a paragraph. I’m imagining implementing that as the text in the paragraph having a :watcher attribute whose value is a process. The stock NSMutableAttributedString code will handle things like adding and deleting characters while keeping the attributes correctly attached. Code wrapped around that will send a changed message to the watcher process (sort of like Observer), which is watching for certain sorts of changes.

For example, if I split a paragraph in two with two blank lines between the chunks, that’s a signal that I’m revising a paragraph. That’s one of the ways I customarily start revisions, and I want the app to asynchronously do certain things to help me out.

So the “paragraph-observer” process will be replaced by a different, “paragraph-editing-observer” process that is alert for different, editing-specific affordances. In particular, it will act to tag internal sentence fragments that will cause the editor display (in the MacOS version) to sweep them off to the side of main editor window. Because I think actions like that will save me hours of frustration at the cost of mere months of coding.

I cover this app in more detail in the last of five Oddly Influenced podcast episodes on ecological and embodied cognition. (Transcript available.)

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement