设计自定义 NSTextView

发布于 2024-12-08 13:34:16 字数 384 浏览 0 评论 0原文

我需要设计一个自定义文本视图来显示我的应用程序生成的日志。日志具有特定的打包二进制格式,每个条目除了实际字符串(日志级别、日期、来源)之外还包括许多字段。现在这些日志可能非常巨大,有数百兆字节的数据。我需要实现基于消息类型/源的快速过滤、搜索、内存布局控制等功能。由于 NSTextView 支持大多数这些功能,我决定从那里开始。

显然,我需要自定义文本存储来提供对打包日志格式的访问,以便在用户滚动日志视图窗口时按需加载新字符串。我还需要根据当前活动过滤器有选择地显示日志行(例如,仅显示警告),而无需再次将整个文本重新加载到视图中,只需在显示时过滤掉这些行。

我查看了 NSTextStorage,它建议重载 -string,这并不完全符合目的。有人可以给我一些指导来指导我进一步的研究吗?我对可可的文本处理比较陌生。

I need to design a custom text view that displays logs that my application produces. Logs have a specific packed binary format, each entry includes a number of fields besides an actual string (log level, date, source). Now these logs can be huge, hundreds of megabytes of data. I need to implement features such all quick filtering based on message type/source, searching, control over memory layout, etc. Since NSTextView supports most of these features i decided to start from there.

I obviously need my custom text storage to provide access to my packed log format, to load new strings on demand when user scrolls the log view window. I also need to selectively display lines of logs based on current active filters (display only warnings for example) without reloading the whole text into the view again, just filtering out the lines as they are displayed.

I have looked at NSTextStorage and it advises to overload -string, which does not exactly fits the purpose. Could anyone please give a couple of pointers to guide my further research? I am relatively new to cocoa's text handling.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱要勇敢去追 2024-12-15 13:34:16

不是对你的问题的直接答案,但可能是对苹果来说足够好的替代方案:

为什么不像 Console.app 那样使用正确的系统日志呢?每个日志条目(尽管可能是多行)都以非常特定的格式开头。 Console.app 使用大纲视图(如果该行对于表行来说太长而无法使所有条目保持相同大小以便于阅读,则该条目具有子行)。在 /Applications/Utilities/Console.app 中的标准日志下查看。

好处:简单地选择整个条目,非常容易的搜索过滤,交替的行颜色使各个条目更容易查看,如果您不喜欢被截断,您可以使用可变行高来显示整个消息/披露方法。

Not a direct answer to your question, but a possible alternative good enough for Apple:

Why not do as Console.app does with proper system logs? Each log entry (though it might be multiple lines) starts with a very specific format. Console.app uses an outline view (an entry has a child row if the line is too long for the table row to keep all entries the same size for easy perusal). Check it out in /Applications/Utilities/Console.app under a standard log.

The benefits: simple selection of entire entry, very easy search filtering, alternating row colors make individual entries easier to see, you could use variable row height to show the whole message if you didn't like the truncated / disclosure approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文